#include <bits/stdc++.h>
using namespace std;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, q;
  cin >> n >> q;
  vector<long long> a(n + 1);
  for (long long i = (1); i <= (n); i++) cin >> a[i];
  vector<pair<long long, long long>> ans, ans2;
  long long maxel = INT_MIN, ind = -1;
  for (long long i = (1); i <= (n); i++) {
    if (maxel < a[i]) {
      maxel = a[i];
      ind = i;
    }
  }
  deque<long long> d, di;
  for (long long i = (1); i <= (n); i++) {
    d.push_back(a[i]);
    di.push_back(i);
  }
  long long ctr = 0;
  while (di[0] != ind) {
    long long temp1, temp2, i1, i2;
    temp1 = d.front();
    i1 = di.front();
    d.pop_front();
    di.pop_front();
    temp2 = d.front();
    i2 = di.front();
    d.pop_front();
    di.pop_front();
    ans.push_back({temp1, temp2});
    ctr++;
    if (temp1 > temp2) {
      d.push_front(temp1);
      di.push_front(i1);
      d.push_back(temp2);
      di.push_back(i2);
    } else {
      d.push_back(temp1);
      di.push_back(i1);
      d.push_front(temp2);
      di.push_front(i2);
    }
  }
  long long ctr2 = 0;
  ctr2++;
  long long ind1 = di[0], ind2 = di[1];
  long long temp1, temp2, i1, i2;
  temp1 = d.front();
  i1 = di.front();
  d.pop_front();
  di.pop_front();
  temp2 = d.front();
  i2 = di.front();
  d.pop_front();
  di.pop_front();
  ans2.push_back({temp1, temp2});
  if (temp1 > temp2) {
    d.push_front(temp1);
    di.push_front(i1);
    d.push_back(temp2);
    di.push_back(i2);
  } else {
    d.push_back(temp1);
    di.push_back(i1);
    d.push_front(temp2);
    di.push_front(i2);
  }
  while (!(di[0] == ind1 && di[1] == ind2)) {
    long long temp1, temp2, i1, i2;
    temp1 = d.front();
    i1 = di.front();
    d.pop_front();
    di.pop_front();
    temp2 = d.front();
    i2 = di.front();
    d.pop_front();
    di.pop_front();
    ans2.push_back({temp1, temp2});
    ctr2++;
    if (temp1 > temp2) {
      d.push_front(temp1);
      di.push_front(i1);
      d.push_back(temp2);
      di.push_back(i2);
    } else {
      d.push_back(temp1);
      di.push_back(i1);
      d.push_front(temp2);
      di.push_front(i2);
    }
  }
  while (q--) {
    long long m;
    cin >> m;
    if (m > ans.size()) {
      m -= ans.size();
      m--;
      cout << ans2[m % ans2.size()].first << " " << ans2[m % ans2.size()].second
           << "\n";
    } else {
      m--;
      cout << ans[m].first << " " << ans[m].second << "\n";
    }
  }
  return 0;
}
