#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int ans[maxn][2];
int res[maxn];
queue<int> que;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int now, maxx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &now);
    que.push(now);
    maxx = max(maxx, now);
  }
  int top1 = que.front();
  que.pop();
  int top2 = que.front();
  que.pop();
  ans[1][0] = top1;
  ans[1][1] = top2;
  int p = 1;
  que.push(min(top1, top2));
  top1 = max(top1, top2);
  while (top1 != maxx) {
    top2 = que.front();
    que.pop();
    p++;
    ans[p][0] = top1;
    ans[p][1] = top2;
    que.push(min(top1, top2));
    top1 = max(top1, top2);
  }
  int rp = 0;
  while (!que.empty()) {
    res[++rp] = que.front();
    que.pop();
  }
  long long question;
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &question);
    if (question <= p)
      printf("%d %d\n", ans[question][0], ans[question][1]);
    else
      printf("%d %d\n", maxx, res[(question - p - 1) % rp + 1]);
  }
}
