/**
 *    author:  tourist
 *    created: 07.09.2022 17:09:38       
**/
#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, q;
  cin >> n >> q;
  vector<pair<int, int>> all;
  for (int a = 1; a <= n; a++) {
    for (int b = 1; b <= n; b++) {
      if (a == 1 && b == 1) {
        continue;
      }
      int x = a;
      int y = b;
      int k = 0;
      while (y > 0) {
        x /= y;
        swap(x, y);
        k += 1;
      }
      int g = max(x, y);
      if (g == __gcd(a, b)) {
        all.emplace_back(a, b);
      }
    }
  }
  while (q--) {
    long long idx;
    cin >> idx;
    --idx;
    if (idx < (int) all.size()) {
      cout << all[idx].first << " " << all[idx].second << '\n';
    } else {
      cout << "-1 -1" << '\n';
    }
  }
  return 0;
}
