#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979;
const long long int mod = 1e9 + 7;
long long int takemod(long long int a, long long int mod) {
  return ((a % mod) + mod) % mod;
}
long long int bs(long long int a[], long long int l, long long int r,
                 long long int x) {
  if (r >= l) {
    long long int mid = (l + r) / 2;
    if (a[mid] == x)
      return mid;
    else if (a[mid] > x)
      return bs(a, l, mid - 1, x);
    else
      return bs(a, mid + 1, r, x);
  }
  return -1;
}
long long int s_t_i(string second) {
  stringstream geek(second);
  long long int m;
  geek >> m;
  return m;
}
long long int power(long long int b, long long int p) {
  if (p == 0)
    return 1;
  else if (p % 2 == 0)
    return (power(b, p / 2) * (power(b, p / 2)));
  else
    return ((b) * (power(b, p - 1)));
}
bool isprime(long long int n) {
  if (n == 1) return false;
  if (n == 2 or n == 3) return true;
  long long int lim = sqrt(n);
  long long int i = 2;
  while (i <= lim) {
    if (n % i == 0) return false;
    i++;
  }
  return true;
}
vector<long long int> factors(long long int n) {
  vector<long long int> a;
  a.push_back(1);
  long long int lim = sqrt(n), i = 2;
  while (i <= lim) {
    if (n % i == 0) {
      a.push_back(i);
      if (i != n / i) a.push_back(n / i);
    }
    i++;
  }
  if (n != 1) a.push_back(n);
  sort(a.begin(), a.end());
  return a;
}
vector<pair<long long int, long long int> > pf_with_count(long long int b) {
  pair<long long int, long long int> p;
  vector<pair<long long int, long long int> > pf;
  long long int count = 0;
  while (b % 2 == 0) {
    b /= 2;
    count++;
  }
  if (count > 0) {
    p.first = 2;
    p.second = count;
    pf.push_back(p);
  }
  long long int i = 3;
  while (i <= sqrt(b)) {
    count = 0;
    while (b % i == 0) {
      b /= i;
      count++;
    }
    if (count > 0) {
      p.first = i;
      p.second = count;
      pf.push_back(p);
    }
    i += 2;
  }
  if (b > 2) {
    p.first = b;
    p.second = 1;
    pf.push_back(p);
  }
  return pf;
}
long long int bs_t_i(string second) {
  long long int l = strtoull(second.c_str(), NULL, 2);
  return l;
}
string i_to_bs(long long int n) {
  string second = bitset<5>(n).to_string();
  return second;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, q;
  cin >> n >> q;
  long long int a[n];
  long long int i = 0;
  while (i < n) {
    cin >> a[i];
    i++;
  }
  long long int ind = -1;
  long long int ma = -1;
  i = 0;
  while (i < n) {
    if (a[i] > ma) {
      ma = a[i];
      ind = i;
    }
    i++;
  }
  vector<long long int> fa;
  i = ind;
  while (i < n) {
    fa.push_back(a[i]);
    i++;
  }
  vector<long long int> v;
  set<pair<long long int, long long int> > st;
  set<pair<long long int, long long int> >::iterator itr1, itr2;
  i = 0;
  while (i <= ind) {
    st.insert(make_pair(i, a[i]));
    i++;
  }
  vector<pair<long long int, long long int> > ans;
  while (st.size() > 1) {
    itr1 = st.begin();
    itr2 = itr1;
    itr2++;
    pair<long long int, long long int> p1 = *itr1;
    pair<long long int, long long int> p2 = *itr2;
    ans.push_back(make_pair(p1.second, p2.second));
    if (p1.second < p2.second) {
      v.push_back(p1.second);
      st.erase(itr1);
    } else {
      v.push_back(p2.second);
      st.erase(itr2);
    }
  }
  i = 0;
  while (i < v.size()) {
    fa.push_back(v[i]);
    i++;
  }
  while (q--) {
    long long int x;
    cin >> x;
    if (x <= ans.size()) {
      cout << ans[x - 1].first << " " << ans[x - 1].second << endl;
    } else {
      long long int k = fa.size() - 1;
      x -= ans.size();
      x %= k;
      if (x == 0)
        cout << fa[0] << " " << fa[k] << endl;
      else
        cout << fa[0] << " " << fa[x] << endl;
    }
  }
}

### Prompt

Construct a cpp code solution to the problem outlined:

Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with n elements. The i-th element is a_i (i = 1, 2, …, n). He gradually takes the first two leftmost elements from the deque (let's call them A and B, respectively), and then does the following: if A > B, he writes A to the beginning and writes B to the end of the deque, otherwise, he writes to the beginning B, and A writes to the end of the deque. We call this sequence of actions an operation.

For example, if deque was [2, 3, 4, 5, 1], on the operation he will write B=3 to the beginning and A=2 to the end, so he will get [3, 4, 5, 1, 2].

The teacher of the course, seeing Valeriy, who was passionate about his work, approached him and gave him q queries. Each query consists of the singular number m_j (j = 1, 2, …, q). It is required for each query to answer which two elements he will pull out on the m_j-th operation.

Note that the queries are independent and for each query the numbers A and B should be printed in the order in which they will be pulled out of the deque.

Deque is a data structure representing a list of elements where insertion of new elements or deletion of existing elements can be made from both sides.

Input

The first line contains two integers n and q (2 ≤ n ≤ 10^5, 0 ≤ q ≤ 3 ⋅ 10^5) — the number of elements in the deque and the number of queries. The second line contains n integers a_1, a_2, ..., a_n, where a_i (0 ≤ a_i ≤ 10^9) — the deque element in i-th position. The next q lines contain one number each, meaning m_j (1 ≤ m_j ≤ 10^{18}).

Output

For each teacher's query, output two numbers A and B — the numbers that Valeriy pulls out of the deque for the m_j-th operation.

Examples

Input


5 3
1 2 3 4 5
1
2
10


Output


1 2
2 3
5 2


Input


2 0
0 0


Output

Note

Consider all 10 steps for the first test in detail:
  1. [1, 2, 3, 4, 5] — on the first operation, A and B are 1 and 2, respectively.

So, 2 we write to the beginning of the deque, and 1 — to the end.

We get the following status of the deque: [2, 3, 4, 5, 1].

  2. [2, 3, 4, 5, 1] ⇒ A = 2, B = 3.
  3. [3, 4, 5, 1, 2]
  4. [4, 5, 1, 2, 3]
  5. [5, 1, 2, 3, 4]
  6. [5, 2, 3, 4, 1]
  7. [5, 3, 4, 1, 2]
  8. [5, 4, 1, 2, 3]
  9. [5, 1, 2, 3, 4]
  10. [5, 2, 3, 4, 1] ⇒ A = 5, B = 2. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979;
const long long int mod = 1e9 + 7;
long long int takemod(long long int a, long long int mod) {
  return ((a % mod) + mod) % mod;
}
long long int bs(long long int a[], long long int l, long long int r,
                 long long int x) {
  if (r >= l) {
    long long int mid = (l + r) / 2;
    if (a[mid] == x)
      return mid;
    else if (a[mid] > x)
      return bs(a, l, mid - 1, x);
    else
      return bs(a, mid + 1, r, x);
  }
  return -1;
}
long long int s_t_i(string second) {
  stringstream geek(second);
  long long int m;
  geek >> m;
  return m;
}
long long int power(long long int b, long long int p) {
  if (p == 0)
    return 1;
  else if (p % 2 == 0)
    return (power(b, p / 2) * (power(b, p / 2)));
  else
    return ((b) * (power(b, p - 1)));
}
bool isprime(long long int n) {
  if (n == 1) return false;
  if (n == 2 or n == 3) return true;
  long long int lim = sqrt(n);
  long long int i = 2;
  while (i <= lim) {
    if (n % i == 0) return false;
    i++;
  }
  return true;
}
vector<long long int> factors(long long int n) {
  vector<long long int> a;
  a.push_back(1);
  long long int lim = sqrt(n), i = 2;
  while (i <= lim) {
    if (n % i == 0) {
      a.push_back(i);
      if (i != n / i) a.push_back(n / i);
    }
    i++;
  }
  if (n != 1) a.push_back(n);
  sort(a.begin(), a.end());
  return a;
}
vector<pair<long long int, long long int> > pf_with_count(long long int b) {
  pair<long long int, long long int> p;
  vector<pair<long long int, long long int> > pf;
  long long int count = 0;
  while (b % 2 == 0) {
    b /= 2;
    count++;
  }
  if (count > 0) {
    p.first = 2;
    p.second = count;
    pf.push_back(p);
  }
  long long int i = 3;
  while (i <= sqrt(b)) {
    count = 0;
    while (b % i == 0) {
      b /= i;
      count++;
    }
    if (count > 0) {
      p.first = i;
      p.second = count;
      pf.push_back(p);
    }
    i += 2;
  }
  if (b > 2) {
    p.first = b;
    p.second = 1;
    pf.push_back(p);
  }
  return pf;
}
long long int bs_t_i(string second) {
  long long int l = strtoull(second.c_str(), NULL, 2);
  return l;
}
string i_to_bs(long long int n) {
  string second = bitset<5>(n).to_string();
  return second;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, q;
  cin >> n >> q;
  long long int a[n];
  long long int i = 0;
  while (i < n) {
    cin >> a[i];
    i++;
  }
  long long int ind = -1;
  long long int ma = -1;
  i = 0;
  while (i < n) {
    if (a[i] > ma) {
      ma = a[i];
      ind = i;
    }
    i++;
  }
  vector<long long int> fa;
  i = ind;
  while (i < n) {
    fa.push_back(a[i]);
    i++;
  }
  vector<long long int> v;
  set<pair<long long int, long long int> > st;
  set<pair<long long int, long long int> >::iterator itr1, itr2;
  i = 0;
  while (i <= ind) {
    st.insert(make_pair(i, a[i]));
    i++;
  }
  vector<pair<long long int, long long int> > ans;
  while (st.size() > 1) {
    itr1 = st.begin();
    itr2 = itr1;
    itr2++;
    pair<long long int, long long int> p1 = *itr1;
    pair<long long int, long long int> p2 = *itr2;
    ans.push_back(make_pair(p1.second, p2.second));
    if (p1.second < p2.second) {
      v.push_back(p1.second);
      st.erase(itr1);
    } else {
      v.push_back(p2.second);
      st.erase(itr2);
    }
  }
  i = 0;
  while (i < v.size()) {
    fa.push_back(v[i]);
    i++;
  }
  while (q--) {
    long long int x;
    cin >> x;
    if (x <= ans.size()) {
      cout << ans[x - 1].first << " " << ans[x - 1].second << endl;
    } else {
      long long int k = fa.size() - 1;
      x -= ans.size();
      x %= k;
      if (x == 0)
        cout << fa[0] << " " << fa[k] << endl;
      else
        cout << fa[0] << " " << fa[x] << endl;
    }
  }
}

```