#include <bits/stdc++.h>
using namespace std;
vector<long long> queries, dq;
vector<pair<int, int>> ans;
int main() {
  ios_base::sync_with_stdio(false);
  int n, q, op = 0;
  long long lar = -1;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    lar = max(lar, x);
    dq.push_back(x);
  }
  if (q == 0) return 0;
  for (int i = 0; i < q; i++) {
    long long x;
    cin >> x;
    queries.push_back(x);
  }
  while (dq[0] != lar) {
    op++;
    int f1, f2;
    f1 = dq[0];
    f2 = dq[1];
    if (f1 > f2) {
      dq.push_back(f2);
      dq.erase(dq.begin() + 1);
    } else {
      dq.push_back(f1);
      dq.erase(dq.begin());
    }
    ans.push_back({f1, f2});
  }
  for (int i = 0; i < queries.size(); i++) {
    if (queries[i] <= op) {
      cout << ans[queries[i] - 1].first << ' ' << ans[queries[i] - 1].second
           << endl;
    } else {
      int b = (queries[i] - (op + 1)) % (n - 1) + 1;
      cout << lar << ' ' << dq[b] << endl;
    }
  }
}
