description: You have a permutation: an array a = [a_1, a_2, …, a_n] of distinct integers from 1 to n. The length of the permutation n is odd.
  
  Consider the following algorithm of sorting the permutation in increasing order.
  
  A helper procedure of the algorithm, f(i), takes a single argument i (1 ≤ i ≤ n-1) and does the following. If a_i > a_{i+1}, the values of a_i and a_{i+1} are exchanged. Otherwise, the permutation doesn't change.
  
  The algorithm consists of iterations, numbered with consecutive integers starting with 1. On the i-th iteration, the algorithm does the following: 
  
    * if i is odd, call f(1), f(3), …, f(n - 2); 
    * if i is even, call f(2), f(4), …, f(n - 1). 
  
  
  
  It can be proven that after a finite number of iterations the permutation will be sorted in increasing order.
  
  After how many iterations will this happen for the first time?
  
  Input
  
  Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 100). Description of the test cases follows.
  
  The first line of each test case contains a single integer n (3 ≤ n ≤ 999; n is odd) — the length of the permutation.
  
  The second line contains n distinct integers a_1, a_2, …, a_n (1 ≤ a_i ≤ n) — the permutation itself. 
  
  It is guaranteed that the sum of n over all test cases does not exceed 999.
  
  Output
  
  For each test case print the number of iterations after which the permutation will become sorted in increasing order for the first time.
  
  If the given permutation is already sorted, print 0.
  
  Example
  
  Input
  
  
  3
  3
  3 2 1
  7
  4 5 7 1 3 2 6
  5
  1 2 3 4 5
  
  
  Output
  
  
  3
  5
  0
  
  Note
  
  In the first test case, the permutation will be changing as follows: 
  
    * after the 1-st iteration: [2, 3, 1]; 
    * after the 2-nd iteration: [2, 1, 3]; 
    * after the 3-rd iteration: [1, 2, 3]. 
  
  
  
  In the second test case, the permutation will be changing as follows: 
  
    * after the 1-st iteration: [4, 5, 1, 7, 2, 3, 6]; 
    * after the 2-nd iteration: [4, 1, 5, 2, 7, 3, 6]; 
    * after the 3-rd iteration: [1, 4, 2, 5, 3, 7, 6]; 
    * after the 4-th iteration: [1, 2, 4, 3, 5, 6, 7]; 
    * after the 5-th iteration: [1, 2, 3, 4, 5, 6, 7]. 
  
  
  
  In the third test case, the permutation is already sorted and the answer is 0.
solution: import java.util.*;
  import java.io.*;
  
  public class A {
  
      public void prayGod() throws IOException {
          int t = nextInt();
          while (t-- > 0) {
              int n = nextInt();
              int[] a = nextIntArray(n);
  
              int ret = 0;
  
              int i = 0;
              while (true) {
                  boolean sorted = true;
                  for (int j = 1; j < n; j++) {
                      if (a[j] < a[j - 1]) {
                          sorted = false;
                          break;
                      }
                  }
                  if (sorted)
                      break;
                  if (i % 2 == 0) {
                      for (int j = 0; j + 1 < n && j < n; j += 2) {
                          if (a[j] > a[j + 1]) {
                              int temp = a[j];
                              a[j] = a[j + 1];
                              a[j + 1] = temp;
                          }
                      }
                  } else {
                      for (int j = 1; j + 1 < n && j < n; j += 2) {
                          if (a[j] > a[j + 1]) {
                              int temp = a[j];
                              a[j] = a[j + 1];
                              a[j + 1] = temp;
                          }
                      }
                  }
                  ret++;
                  i++;
              }
  
              out.println(ret);
  
          }
      }
  
      public void printVerdict(boolean verdict) {
          if (verdict)
              out.println(VERDICT_YES);
          else
              out.println(VERDICT_NO);
      }
  
      static final String VERDICT_YES = "Yes";
      static final String VERDICT_NO = "No";
      static final boolean RUN_TIMING = true;
      static final boolean AUTOFLUSH = false;
      static final boolean FILE_INPUT = false;
      static final boolean FILE_OUTPUT = false;
  
      static int iinf = 0x3f3f3f3f;
      static long inf = (long) 1e18 + 10;
      static long mod = (long) 1e9 + 7;
  
      static char[] inputBuffer = new char[1 << 20];
      static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1 << 20);
      static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), AUTOFLUSH);
  
      // int data-type
      public int nextInt() throws IOException {
          return Integer.parseInt(next());
      }
  
      public int[] nextIntArray(int n) throws IOException {
          int[] arr = new int[n];
          for (int i = 0; i < n; i++)
              arr[i] = nextInt();
          return arr;
      }
  
      public void sort(int[] a) {
          shuffle(a);
          Arrays.sort(a);
      }
  
      public static void printArray(int[] arr) {
          for (int i = 0; i < arr.length; i++)
              out.print(arr[i] + " ");
          out.println();
      }
  
      // long data-type
      public long nextLong() throws IOException {
          return Long.parseLong(next());
      }
  
      public long[] nextLongArray(int n) throws IOException {
          long[] arr = new long[n];
          for (int i = 0; i < n; i++)
              arr[i] = nextLong();
          return arr;
      }
  
      public static void printArray(long[] arr) {
          for (int i = 0; i < arr.length; i++)
              out.print(arr[i] + " ");
          out.println();
      }
  
      public void sort(long[] a) {
          shuffle(a);
          Arrays.sort(a);
      }
  
      // double data-type
      public double nextDouble() throws IOException {
          return Double.parseDouble(next());
      }
  
      public double[] nextDoubleArray(int n) throws IOException {
          double[] arr = new double[n];
          for (int i = 0; i < n; i++)
              arr[i] = nextDouble();
          return arr;
      }
  
      public static void printArray(double[] arr) {
          for (int i = 0; i < arr.length; i++)
              out.print(arr[i] + " ");
          out.println();
      }
  
      // Generic type
      public <T> void sort(T[] a) {
          shuffle(a);
          Arrays.sort(a);
      }
  
      public static <T> void printArray(T[] arr) {
          for (int i = 0; i < arr.length; i++)
              out.print(arr[i] + " ");
          out.println();
      }
  
      public String next() throws IOException {
          int len = 0;
          int c;
          do {
              c = in.read();
          } while (Character.isWhitespace(c) && c != -1);
          if (c == -1) {
              throw new NoSuchElementException("Reached EOF");
          }
          do {
              inputBuffer[len] = (char) c;
              len++;
              c = in.read();
          } while (!Character.isWhitespace(c) && c != -1);
          while (c != '\n' && Character.isWhitespace(c) && c != -1) {
              c = in.read();
          }
          if (c != -1 && c != '\n') {
              in.unread(c);
          }
          return new String(inputBuffer, 0, len);
      }
  
      public String nextLine() throws IOException {
          int len = 0;
          int c;
          while ((c = in.read()) != '\n' && c != -1) {
              if (c == '\r') {
                  continue;
              }
              inputBuffer[len] = (char) c;
              len++;
          }
          return new String(inputBuffer, 0, len);
      }
  
      public boolean hasNext() throws IOException {
          String line = nextLine();
          if (line.isEmpty()) {
              return false;
          }
          in.unread('\n');
          in.unread(line.toCharArray());
          return true;
      }
  
      public void shuffle(int[] arr) {
          int n = arr.length;
          for (int i = 0; i < n; i++) {
              int j = (int) (Math.random() * (n - i));
              int temp = arr[i];
              arr[i] = arr[j];
              arr[j] = temp;
          }
      }
  
      public void shuffle(long[] arr) {
          int n = arr.length;
          for (int i = 0; i < n; i++) {
              int j = (int) (Math.random() * (n - i));
              long temp = arr[i];
              arr[i] = arr[j];
              arr[j] = temp;
          }
      }
  
      public void shuffle(Object[] arr) {
          int n = arr.length;
          for (int i = 0; i < n; i++) {
              int j = (int) (Math.random() * (n - i));
              Object temp = arr[i];
              arr[i] = arr[j];
              arr[j] = temp;
          }
      }
  
      public static void main(String[] args) throws IOException {
          if (FILE_INPUT)
              in = new PushbackReader(new BufferedReader(new FileReader(new File("output.txt"))), 1 << 20);
          if (FILE_OUTPUT)
              out = new PrintWriter(new FileWriter(new File("output.txt")));
  
          long time = 0;
          time -= System.nanoTime();
          new A().prayGod();
          time += System.nanoTime();
  
          if (RUN_TIMING)
              System.err.printf("%.3f ms%n", time / 1000000.0);
  
          out.flush();
          in.close();
      }
  }
  