#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-12;
const int inf = 2000000000;
const long long int infLL = (long long int)1e18;
long long int MOD = 1000000007;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
  return n & (1LL << i);
}
inline long long int setBit(long long int n, long long int i) {
  return n | (1LL << i);
  ;
}
inline long long int resetBit(long long int n, long long int i) {
  return n & (~(1LL << i));
}
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long int year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long int &a) {
  a %= MOD;
  (a < 0) && (a += MOD);
}
inline long long int modMul(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline long long int modAdd(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline long long int modSub(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long int modPow(long long int b, long long int p) {
  long long int r = 1LL;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1LL;
  }
  return r;
}
inline long long int modDiv(long long int a, long long int b) {
  return modMul(a, modPow(b, MOD - 2));
}
bool comp(const pair<long long int, pair<long long int, long long int> > &p1,
          const pair<long long int, pair<long long int, long long int> > &p2) {
  return p1.first > p2.first;
}
bool comp1(const pair<long long int, long long int> &p1,
           const pair<long long int, long long int> &p2) {
  if (p1.first == p2.first) {
    return p1.second > p2.second;
  }
  return p1.first < p2.first;
}
long long int converter(string a) {
  long long int i, mul = 1LL, r, t, ans = 0LL;
  if (a.length() == 0) return 0;
  for (i = a.length() - 1; i >= 0; i--) {
    t = a[i] - '0';
    r = t % 10;
    ans += (mul * r);
    mul = mul * 10;
  }
  return ans;
}
int msb(unsigned x) {
  union {
    double a;
    int b[2];
  };
  a = x;
  return (b[1] >> 20) - 1023;
}
const int MAX = 300005;
deque<long long int> dq;
long long int a[MAX];
long long int i, x, y, n, q;
vector<pair<long long int, long long int> > qu;
long long int ans1[MAX], ans2[MAX];
long long int stp1[MAX], stp2[MAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.unsetf(ios::floatfield);
  cout.precision(20);
  cout.setf(ios::fixed, ios::floatfield);
  ;
  cin >> n >> q;
  long long int maxi = -1LL;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    dq.push_back(a[i]);
    maxi = max(maxi, a[i]);
  }
  for (i = 1; i <= q; ++i) {
    cin >> x;
    qu.push_back({x, i});
  }
  sort((qu).begin(), (qu).end());
  long long int j = 0;
  while (1) {
    x = dq.front();
    dq.pop_front();
    y = dq.front();
    dq.pop_front();
    stp1[++j] = x;
    stp2[j] = y;
    if (x > y) {
      dq.push_front(x);
      dq.push_back(y);
    } else {
      dq.push_front(y);
      dq.push_back(x);
    }
    if (x == maxi) break;
  }
  dq.pop_front();
  for (i = 2; i <= n; ++i) {
    a[i - 1] = dq.front();
    dq.pop_front();
  }
  for (i = 0; i < q; ++i) {
    long long int now = qu[i].first;
    long long int id = qu[i].second;
    if (now <= j) {
      ans1[id] = stp1[now];
      ans2[id] = stp2[now];
    } else {
      now -= j;
      long long int pos = now % (n - 1);
      if (pos == 0) pos = n - 1;
      ans1[id] = maxi;
      ans2[id] = a[pos];
    }
  }
  for (i = 1; i <= q; ++i) {
    cout << ans1[i] << " " << ans2[i] << '\n';
  }
  return 0;
}

### Prompt

Your challenge is to write a Cpp solution to the following problem:

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 double PI = acos(-1);
const double eps = 1e-12;
const int inf = 2000000000;
const long long int infLL = (long long int)1e18;
long long int MOD = 1000000007;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
  return n & (1LL << i);
}
inline long long int setBit(long long int n, long long int i) {
  return n | (1LL << i);
  ;
}
inline long long int resetBit(long long int n, long long int i) {
  return n & (~(1LL << i));
}
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(long long int year) {
  return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
inline void normal(long long int &a) {
  a %= MOD;
  (a < 0) && (a += MOD);
}
inline long long int modMul(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline long long int modAdd(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline long long int modSub(long long int a, long long int b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline long long int modPow(long long int b, long long int p) {
  long long int r = 1LL;
  while (p) {
    if (p & 1) r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1LL;
  }
  return r;
}
inline long long int modDiv(long long int a, long long int b) {
  return modMul(a, modPow(b, MOD - 2));
}
bool comp(const pair<long long int, pair<long long int, long long int> > &p1,
          const pair<long long int, pair<long long int, long long int> > &p2) {
  return p1.first > p2.first;
}
bool comp1(const pair<long long int, long long int> &p1,
           const pair<long long int, long long int> &p2) {
  if (p1.first == p2.first) {
    return p1.second > p2.second;
  }
  return p1.first < p2.first;
}
long long int converter(string a) {
  long long int i, mul = 1LL, r, t, ans = 0LL;
  if (a.length() == 0) return 0;
  for (i = a.length() - 1; i >= 0; i--) {
    t = a[i] - '0';
    r = t % 10;
    ans += (mul * r);
    mul = mul * 10;
  }
  return ans;
}
int msb(unsigned x) {
  union {
    double a;
    int b[2];
  };
  a = x;
  return (b[1] >> 20) - 1023;
}
const int MAX = 300005;
deque<long long int> dq;
long long int a[MAX];
long long int i, x, y, n, q;
vector<pair<long long int, long long int> > qu;
long long int ans1[MAX], ans2[MAX];
long long int stp1[MAX], stp2[MAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout.unsetf(ios::floatfield);
  cout.precision(20);
  cout.setf(ios::fixed, ios::floatfield);
  ;
  cin >> n >> q;
  long long int maxi = -1LL;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
    dq.push_back(a[i]);
    maxi = max(maxi, a[i]);
  }
  for (i = 1; i <= q; ++i) {
    cin >> x;
    qu.push_back({x, i});
  }
  sort((qu).begin(), (qu).end());
  long long int j = 0;
  while (1) {
    x = dq.front();
    dq.pop_front();
    y = dq.front();
    dq.pop_front();
    stp1[++j] = x;
    stp2[j] = y;
    if (x > y) {
      dq.push_front(x);
      dq.push_back(y);
    } else {
      dq.push_front(y);
      dq.push_back(x);
    }
    if (x == maxi) break;
  }
  dq.pop_front();
  for (i = 2; i <= n; ++i) {
    a[i - 1] = dq.front();
    dq.pop_front();
  }
  for (i = 0; i < q; ++i) {
    long long int now = qu[i].first;
    long long int id = qu[i].second;
    if (now <= j) {
      ans1[id] = stp1[now];
      ans2[id] = stp2[now];
    } else {
      now -= j;
      long long int pos = now % (n - 1);
      if (pos == 0) pos = n - 1;
      ans1[id] = maxi;
      ans2[id] = a[pos];
    }
  }
  for (i = 1; i <= q; ++i) {
    cout << ans1[i] << " " << ans2[i] << '\n';
  }
  return 0;
}

```