import java.math.BigInteger; import java.util.Scanner; public class Main { static BigInteger f(long n, long a, long b) { BigInteger N = BigInteger.valueOf(n); BigInteger A = BigInteger.valueOf(a); BigInteger B = BigInteger.valueOf(b); BigInteger res = N.multiply(N).multiply(N).multiply(B) .add(N.subtract(BigInteger.ONE).multiply(N).multiply(N).multiply(A)); if (n % 2 == 0) { BigInteger tmp = BigInteger.valueOf(n / 2).multiply(BigInteger.valueOf(n / 2)) .multiply(BigInteger.valueOf(18)).multiply(A); tmp = tmp.add(BigInteger.valueOf(7).multiply(f(n / 2, a, b))); res = res.min(tmp); } return res; } public static void main(String[] args) { Scanner input = new Scanner(System.in); int mod = 1000000007; int T = input.nextInt(); for (int i = 0; i < T; i++) { long n = input.nextLong(); long a = input.nextLong(); long b = input.nextLong(); BigInteger res = f(n, a, b); System.out.println(res.mod(BigInteger.valueOf(mod))); } } }