#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  deque<long long> de;
  vector<long long> vec;
  map<long long, pair<long long, long long>> ma;
  long long maxx = -1;
  for (long long i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    vec.push_back(a);
    maxx = max(maxx, a);
  }
  for (long long i = 0; i < n; ++i) {
    de.push_back(vec[i]);
  }
  long long i = 0;
  while (de.front() != maxx) {
    long long a = de.front();
    de.pop_front();
    long long b = de.front();
    de.pop_front();
    ma[i + 1] = {a, b};
    if (b > a) {
      de.push_back(a);
      de.push_front(b);
    } else {
      de.push_back(b);
      de.push_front(a);
    }
    i++;
  }
  de.pop_front();
  vector<long long> res;
  while (!de.empty()) {
    res.push_back(de.front());
    de.pop_front();
  }
  for (long long j = 0; j < m; ++j) {
    long long a;
    cin >> a;
    if (ma.count(a) != 0) {
      cout << ma[a].first << " " << ma[a].second << endl;
    } else {
      a -= (i + 1);
      cout << maxx << " " << res[(a) % res.size()] << endl;
    }
  }
}
