import java.io.*; import java.util.*; import java.math.*; public class Main { public static BigInteger min(BigInteger a,BigInteger b) { if(a.compareTo(BigInteger.valueOf(-1))==0) return b; else if(b.compareTo(BigInteger.valueOf(-1))==0) return a; else { if(a.compareTo(b)<0) return a; else return b; } } public static BigInteger Normal(long n, int a, int b) { BigInteger v1 = BigInteger.valueOf(n); v1 = v1.multiply(BigInteger.valueOf(n)); v1 = v1.multiply(BigInteger.valueOf(n)); v1 = v1.multiply(BigInteger.valueOf(b)); BigInteger v2 = BigInteger.valueOf(n - 1); v2 = v2.multiply(BigInteger.valueOf(n)); v2 = v2.multiply(BigInteger.valueOf(n)); v2 = v2.multiply(BigInteger.valueOf(a)); BigInteger res = v1.add(v2); return res; } public static BigInteger Strassen(long n, int a, int b) { BigInteger v1 = BigInteger.valueOf(n / 2); v1 = v1.multiply(BigInteger.valueOf(n / 2)); v1 = v1.multiply(BigInteger.valueOf(18)); v1 = v1.multiply(BigInteger.valueOf(a)); BigInteger v2 = solve(n / 2, a, b); v2 = v2.multiply(BigInteger.valueOf(7)); BigInteger res = v1.add(v2); return res; } public static BigInteger solve(long n, int a, int b) { if (n % 2 == 1) { return Normal(n, a, b); } else { BigInteger res = Normal(n, a, b); res = min(res, Strassen(n, a, b)); return res; } } public static void main(String args[]) throws IOException { Scanner cin = new Scanner(System.in); // 重定向 // Scanner cin = new Scanner(new File("input.txt")); //读入 int T = cin.nextInt(); for (int case_ = 0; case_ < T; case_++) { long n = cin.nextLong(); int a = cin.nextInt(); int b = cin.nextInt(); BigInteger res = solve(n, a, b); res = res.mod(BigInteger.valueOf(1000000000 + 7)); System.out.println(res); } } }