public static void main(String[] args) throws Exception {

    /*  BufferedReader br=new BufferedReader(new FileReader("input.txt"));
        BufferedWriter out=new BufferedWriter(new FileWriter("output.txt"));
    */
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 2000);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 2000);
    String[] s = br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    int q = Integer.parseInt(s[1]);
    int num[] = new int[n + 1];
    int[] m = new int[3 * n + 1]; // size = 2*n+1
    Arrays.fill(num, -1);
    s = br.readLine().split(" ");
    for (int i = 1; i <= n; i++) num[i] = Integer.parseInt(s[i - 1]);
    /// build tree
    maketree(1, 1, n, m, num);

    for (int qq = 1; qq <= q; qq++) {
      s = br.readLine().split(" ");
      int i = Integer.parseInt(s[0]);
      int j = Integer.parseInt(s[1]);
      int ans = query(1, 1, n, m, num, i, j);
      out.write("" + num[ans] + "\n");
      out.flush();
    }
  }
  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    // byte digit[]=new byte[101];
    // boolean[] check=new boolean[101];
    // int num[]=new int[99999];
    ans = 0;
    int tests = Integer.parseInt(br.readLine());
    BigInteger f[] = new BigInteger[101];

    for (int i = 1; i <= 100; i++) {
      f[i] = new BigInteger(("" + i));
    }
    for (int i = 2; i <= 100; i++) {
      f[i] = f[i].multiply(f[i - 1]);
    }

    for (int i = 0; i < tests; i++) {

      int n = Integer.parseInt(br.readLine());
      out.write("\n" + f[n].toString());
      out.flush();
    }
  }