/**
 *    author:  tourist
 *    created: 16.09.2022 16:14:15       
**/
#undef _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> at(n + 1);
  for (int i = 2; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      int a = i;
      int b = j / i;
      while (b > 0) {
        a /= b;
        swap(a, b);
      }
      if (i % a != 0) {
        continue;
      }
      int from = j - j % a;
      if (from < j) {
        from += a;
      }
      for (int k = from; k < min(n + 1, j + i); k += a) {
        if (__gcd(k, i) == a) {
          at[k].push_back(i);
        }
      }
    }
  }
  vector<pair<int, int>> all;
  for (int i = 1; i <= n; i++) {
    for (int j : at[i]) {
      all.emplace_back(i, j);
    }
  }
  int tt;
  cin >> tt;
  while (tt--) {
    long long id;
    cin >> id;
    --id;
    if (0 <= id && id < (int) all.size()) {
      cout << all[id].first << " " << all[id].second << '\n';
    } else {
      cout << -1 << " " << -1 << '\n';
    }
  }
  return 0;
}
