#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 5;
deque<int> Q;
long long q[N * 5];
pair<int, int> f[N * 5];
map<pair<int, int>, bool> mm;
int main() {
  int n, m, b;
  int mx = 0, tot = 0;
  ;
  cin >> n >> m;
  for (int i = (int)(1); i <= (int)(n); i++)
    scanf("%d", &b), mx = max(mx, b), Q.push_back(b);
  for (int i = (int)(1); i <= (int)(m); i++) scanf("%lld", &q[i]);
  for (int i = (int)(1); i <= (int)((n - 1) * 2); i++) {
    int x = Q.front();
    Q.pop_front();
    int y = Q.front();
    Q.pop_front();
    f[i].first = x, f[i].second = y;
    if (x > y)
      Q.push_front(x), Q.push_back(y);
    else
      Q.push_front(y), Q.push_back(x);
    tot++;
    if (Q.front() == mx) break;
  }
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x = Q.front();
    Q.pop_front();
    int y = Q.front();
    Q.pop_front();
    f[tot + i].first = x;
    f[tot + i].second = y;
    Q.push_front(x), Q.push_back(y);
  }
  for (int i = (int)(1); i <= (int)(m); i++) {
    if (q[i] <= tot) {
      printf("%d %d\n", f[q[i]].first, f[q[i]].second);
    } else {
      printf("%d %d\n", f[tot + (q[i] - tot - 1) % (n - 1) + 1].first,
             f[tot + (q[i] - tot - 1) % (n - 1) + 1].second);
    }
  }
  return 0;
}
