#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1e6 + 7;
pair<int, int> dp[MAXN];
pair<int, int> Move(deque<int>& q) {
  int a = q.front();
  q.pop_front();
  int b = q.front();
  q.pop_front();
  if (a < b) {
    q.push_front(b);
    q.push_back(a);
  } else {
    q.push_front(a);
    q.push_back(b);
  }
  return make_pair(a, b);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  ll m;
  cin >> n >> q;
  deque<int> a(n);
  for (int& x : a) cin >> x;
  for (int i = 1; i <= 1000000; i++) {
    dp[i] = Move(a);
  }
  for (int i = 0; i < q; i++) {
    cin >> m;
    if (m > 1000000) m = m % (n - 1) + 2 * (n - 1);
    cout << dp[m].first << ' ' << dp[m].second << '\n';
  }
  return 0;
}
