publicclassMain{ publicstaticvoidmain(String[] args){ Scanner in = new Scanner(System.in); int T; T = in.nextInt(); while(T > 0) { T--; BigInteger a, b, n; n = in.nextBigInteger(); a = in.nextBigInteger(); b = in.nextBigInteger(); BigInteger ans = f(n, a, b); BigInteger mod = new BigInteger("1000000007"); System.out.println(ans.remainder(mod)); } } publicstatic BigInteger f(BigInteger n, BigInteger a, BigInteger b){ BigInteger c = new BigInteger("18"); BigInteger d = new BigInteger("7"); BigInteger e = new BigInteger("2"); if((n).equals(BigInteger.ONE)) { return b; } return ( ( (n.pow(3)).multiply(b) ).add( ((n.subtract(BigInteger.ONE)).multiply(n.pow(2))).multiply(a) ) ).min( ( (c.multiply( ((n.divide(e)).pow(2)) )).multiply(a) ).add( (d.multiply(f(n.divide(e), a, b))) ) ); } }