#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, q;
  cin >> n >> q;
  deque<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<long long> lst(q);
  for (long long i = 0; i < q; i++) cin >> lst[i];
  long long pos = 0;
  for (long long i = 0; i < n; i++) {
    if (a[i] > a[pos]) {
      pos = i;
    }
  }
  vector<pair<long long, long long>> ans(pos);
  if (pos != 0) {
    ans[0] = {a[0], a[1]};
  }
  for (long long i = 1; i < pos; i++) {
    long long num1 = a[0];
    long long num2 = a[1];
    a.pop_front();
    a.pop_front();
    if (num1 > num2) {
      a.push_front(num1);
      a.push_back(num2);
    } else {
      a.push_front(num2);
      a.push_back(num1);
    }
    ans[i] = {a[0], a[1]};
  }
  vector<pair<long long, long long>> circle(n - 1);
  long long it = 0;
  if (pos == 0) {
    it = 1;
    circle[0] = {a[0], a[1]};
  }
  for (long long i = it; i < n - 1; i++) {
    long long num1 = a[0];
    long long num2 = a[1];
    a.pop_front();
    a.pop_front();
    if (num1 > num2) {
      a.push_front(num1);
      a.push_back(num2);
    } else {
      a.push_front(num2);
      a.push_back(num1);
    }
    circle[i] = {a[0], a[1]};
  }
  for (auto j : lst) {
    if (j <= ans.size()) {
      cout << ans[j - 1].first << " " << ans[j - 1].second << "\n";
    } else {
      j -= ans.size();
      cout << circle[(j - 1) % (n - 1)].first << " "
           << circle[(j - 1) % (n - 1)].second << "\n";
    }
  }
  return 0;
}
