description: You are given n lengths of segments that need to be placed on an infinite axis with coordinates.
  
  The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate 0. Let's call this endpoint the "start" of the first segment and let's call its "end" as that endpoint that is not the start. 
  
  The "start" of each following segment must coincide with the "end" of the previous one. Thus, if the length of the next segment is d and the "end" of the previous one has the coordinate x, the segment can be placed either on the coordinates [x-d, x], and then the coordinate of its "end" is x - d, or on the coordinates [x, x+d], in which case its "end" coordinate is x + d.
  
  The total coverage of the axis by these segments is defined as their overall union which is basically the set of points covered by at least one of the segments. It's easy to show that the coverage will also be a segment on the axis. Determine the minimal possible length of the coverage that can be obtained by placing all the segments on the axis without changing their order.
  
  Input
  
  The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.
  
  The next 2t lines contain descriptions of the test cases. 
  
  The first line of each test case description contains an integer n (1 ≤ n ≤ 10^4) — the number of segments. The second line of the description contains n space-separated integers a_i (1 ≤ a_i ≤ 1000) — lengths of the segments in the same order they should be placed on the axis.
  
  It is guaranteed that the sum of n over all test cases does not exceed 10^4.
  
  Output
  
  Print t lines, each line containing the answer to the corresponding test case. The answer to a test case should be a single integer — the minimal possible length of the axis coverage.
  
  Example
  
  Input
  
  
  6
  2
  1 3
  3
  1 2 3
  4
  6 2 3 9
  4
  6 8 4 5
  7
  1 2 4 6 7 7 3
  8
  8 6 5 1 2 2 3 6
  
  
  Output
  
  
  3
  3
  9
  9
  7
  8
  
  Note
  
  In the third sample test case the segments should be arranged as follows: [0, 6] → [4, 6] → [4, 7] → [-2, 7]. As you can see, the last segment [-2, 7] covers all the previous ones, and the total length of coverage is 9.
  
  In the fourth sample test case the segments should be arranged as [0, 6] → [-2, 6] → [-2, 2] → [2, 7]. The union of these segments also occupies the area [-2, 7] and has the length of 9.
solution: import java.io.OutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.PrintWriter;
  import java.util.Arrays;
  import java.util.InputMismatchException;
  import java.io.IOException;
  import java.io.InputStream;
  
  /**
   * Built using CHelper plug-in
   * Actual solution is at the top
   */
  public class Main {
  
      public static void main(String[] args) {
          InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          InputReader in = new InputReader(inputStream);
          PrintWriter out = new PrintWriter(outputStream);
          GMinimalnoePokritie solver = new GMinimalnoePokritie();
          int testCount = Integer.parseInt(in.next());
          for (int i = 1; i <= testCount; i++) {
              solver.solve(i, in, out);
          }
          out.close();
      }
  
      static class GMinimalnoePokritie {
  
          public void solve(int testNumber, InputReader in, PrintWriter out) {
              int n = in.nextInt();
              int[] a = new int[n];
              for (int i = 0; i < n; i++) {
                  a[i] = in.nextInt();
              }
              int m = 2020;
              int mid = m / 2;
              int[] from = new int[m];
              int[] orig = new int[m];
              for (int i = 0; i < m; i++) {
                  if (i >= mid) {
                      from[i] = (i - mid) * 2;
                  } else {
                      from[i] = (mid - i) * 2 - 1;
                  }
              }
              int[] to = new int[m];
              System.arraycopy(from, 0, orig, 0, m);
  
              for (int i = 0; i < n; i++) {
                  Arrays.fill(to, Integer.MAX_VALUE);
                  for (int h = 0; h < m; h++) {
                      if (from[h] == Integer.MAX_VALUE) {
                          continue;
                      }
                      if (h - a[i] >= 0) {
                          to[h - a[i]] = Math.min(to[h - a[i]], Math.max(from[h], orig[h - a[i]]));
                      }
                      if (h + a[i] < m) {
                          to[h + a[i]] = Math.min(to[h + a[i]], Math.max(from[h], orig[h + a[i]]));
                      }
                  }
                  int[] z = from;
                  from = to;
                  to = z;
              }
              int min = Integer.MAX_VALUE;
              for (int i = 0; i < m; i++) {
                  min = Math.min(from[i], min);
              }
              out.println(min);
          }
      }
  
      static class InputReader {
  
          private static final int BUFFER_LENGTH = 1 << 10;
          private InputStream stream;
          private byte[] buf = new byte[BUFFER_LENGTH];
          private int curChar;
          private int numChars;
  
          public InputReader(InputStream stream) {
              this.stream = stream;
          }
  
          private int nextC() {
              if (numChars == -1) {
                  throw new InputMismatchException();
              }
              if (curChar >= numChars) {
                  curChar = 0;
                  try {
                      numChars = stream.read(buf);
                  } catch (IOException e) {
                      throw new InputMismatchException();
                  }
                  if (numChars <= 0) {
                      return -1;
                  }
              }
              return buf[curChar++];
          }
  
          public String next() {
              int c = nextC();
              while (isSpaceChar(c)) {
                  c = nextC();
              }
              StringBuilder res = new StringBuilder();
              do {
                  res.append((char) c);
                  c = nextC();
              } while (!isSpaceChar(c));
              return res.toString();
          }
  
          public int nextInt() {
              int c = skipWhileSpace();
              int sgn = 1;
              if (c == '-') {
                  sgn = -1;
                  c = nextC();
              }
              int res = 0;
              do {
                  if (c < '0' || c > '9') {
                      throw new InputMismatchException();
                  }
                  res *= 10;
                  res += c - '0';
                  c = nextC();
              } while (!isSpaceChar(c));
              return res * sgn;
          }
  
          public int skipWhileSpace() {
              int c = nextC();
              while (isSpaceChar(c)) {
                  c = nextC();
              }
              return c;
          }
  
          public boolean isSpaceChar(int c) {
              return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
          }
      }
  }
  
  