import java.net.*; import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.regex.*; class Main { private static BigInteger a; private static BigInteger b; public static void main(final String[] args) throws Exception { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); while (T-- > 0) { long n = sc.nextLong(); a = new BigInteger(sc.next()); b = new BigInteger(sc.next()); System.out.println(dfs(n).mod(BigInteger.valueOf(1000000007)).toString()); } sc.close(); } private static BigInteger dfs(long n) { BigInteger A = BigInteger.valueOf(n).multiply(BigInteger.valueOf(n)).multiply(BigInteger.valueOf(n)).multiply(b).add(BigInteger.valueOf(n).subtract(BigInteger.valueOf(1)).multiply(BigInteger.valueOf(n)).multiply(BigInteger.valueOf(n)).multiply(a)); if (n % 2 > 0) return A; BigInteger B = BigInteger.valueOf(n).multiply(BigInteger.valueOf(n)).multiply(BigInteger.valueOf(18)).divide(BigInteger.valueOf(4)).multiply(a).add(dfs(n/2).multiply(BigInteger.valueOf(7))); return A.min(B); } }