1. import java.io.OutputStream;
  2. import java.io.IOException;
  3. import java.io.InputStream;
  4. import java.io.PrintWriter;
  5. import java.util.InputMismatchException;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8.  
  9. /**
  10. * Built using CHelper plug-in
  11. * Actual solution is at the top
  12. */
  13. public class Main {
  14. public static void main(String[] args) {
  15. InputStream inputStream = System.in;
  16. OutputStream outputStream = System.out;
  17. MyScan in = new MyScan(inputStream);
  18. PrintWriter out = new PrintWriter(outputStream);
  19. SpecialShop solver = new SpecialShop();
  20. int testCount = Integer.parseInt(in.next());
  21. for (int i = 1; i <= testCount; i++)
  22. solver.solve(i, in, out);
  23. out.close();
  24. }
  25.  
  26. static class SpecialShop {
  27. public void solve(int testNumber, MyScan in, PrintWriter out) {
  28. int n = in.nextInt();
  29. int a = in.nextInt();
  30. int b = in.nextInt();
  31.  
  32.  
  33. out.println(s(n, a, b));
  34.  
  35. }
  36.  
  37. private long s(long n, long a, long b) {
  38. long f1 = n * b / (a + b);
  39.  
  40.  
  41. return Math.min(k(n, a, b, f1), k(n, a, b, f1 + 1));
  42. }
  43.  
  44. private long k(long n, long a, long b, long ind) {
  45. return a * ind * ind + b * (n - ind) * (n - ind);
  46. }
  47.  
  48. }
  49.  
  50. static class MyScan {
  51. private final InputStream in;
  52. private byte[] inbuf = new byte[1024];
  53. public int lenbuf = 0;
  54. public int ptrbuf = 0;
  55.  
  56. public MyScan(InputStream in) {
  57. this.in = in;
  58. }
  59.  
  60. private int readByte() {
  61. if (lenbuf == -1) throw new InputMismatchException();
  62. if (ptrbuf >= lenbuf) {
  63. ptrbuf = 0;
  64. try {
  65. lenbuf = in.read(inbuf);
  66. } catch (IOException e) {
  67. throw new InputMismatchException();
  68. }
  69. if (lenbuf <= 0) return -1;
  70. }
  71. return inbuf[ptrbuf++];
  72. }
  73.  
  74. public boolean isSpaceChar(int c) {
  75. return !(c >= 33 && c <= 126);
  76. }
  77.  
  78. public int skip() {
  79. int b;
  80. while ((b = readByte()) != -1 && isSpaceChar(b)) ;
  81. return b;
  82. }
  83.  
  84. public String next() {
  85. int b = skip();
  86. StringBuilder sb = new StringBuilder();
  87. while (!(isSpaceChar(b))) {
  88. sb.appendCodePoint(b);
  89. b = readByte();
  90. }
  91. return sb.toString();
  92. }
  93.  
  94. public int nextInt() {
  95. int num = 0, b;
  96. boolean minus = false;
  97. while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
  98. if (b == '-') {
  99. minus = true;
  100. b = readByte();
  101. }
  102.  
  103. while (true) {
  104. if (b >= '0' && b <= '9') {
  105. num = num * 10 + (b - '0');
  106. } else {
  107. return minus ? -num : num;
  108. }
  109. b = readByte();
  110. }
  111. }
  112.  
  113. }
  114. }
  115.  
Language: Java 8