#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b, n;
  cin >> a >> b >> n;
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    long long l, t, m, x, k;
    cin >> l >> t >> m;
    x = a + (l - 1) * b;
    k = (t - x) / b;
    if (x > t) {
      cout << -1 << endl;
      continue;
    }
    k = min((long long)((sqrt((2 * x - b) * (2 * x - b) + 8 * b * t * m) -
                         (2 * x + b)) /
                        (2 * b)),
            k);
    cout << l + k << endl;
  }
  return 0;
}
