import java.util.*; import java.math.*; public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); for(int _ = 0; _ < t; _++) { long n, a, b; n = cin.nextLong(); a = cin.nextLong(); b = cin.nextLong(); int x = 0; while(n != 1) { n >>= 1; x++; } BigInteger ans[] = new BigInteger[40]; ans[0] = BigInteger.valueOf(b); for(int __ = 1; __ <= x; __++) { BigInteger now = BigInteger.ONE; for(int ___ = 0; ___ < __; ___++)now = now.multiply(new BigInteger("2")); ans[__] = ans[__ - 1].multiply(new BigInteger("7")); ans[__] = ans[__].add(now.multiply(now).multiply(BigInteger.valueOf(a)).multiply(new BigInteger("9")).divide(new BigInteger("2"))); BigInteger tmp = now.multiply(now).multiply(now).multiply(BigInteger.valueOf(b)).add(BigInteger.valueOf(a).multiply(now).multiply(now).multiply(now.subtract(BigInteger.ONE))); if(tmp.compareTo(ans[__]) == -1)ans[__] = tmp; } System.out.println(ans[x].mod(new BigInteger("1000000007"))); } } }