#include <bits/stdc++.h>
using namespace std;
long long A, B;
long long l, t, m;
int n;
long long work(long long x) { return A + (x - 1) * B; }
long long solve(long long sum) {
  long long Y, X, a, b, ans1;
  X = 2 * A + (l - 2) * B;
  Y = 1 - l;
  a = B;
  b = X + B * Y;
  long long ans = (-1 * b + sqrt(b * b - 4 * a * (X * Y - 2 * sum))) / 2 / a;
  if ((B * ans * ans + ans * (X + B * Y) + X * Y) <= 2 * sum)
    ans1 = ans;
  else {
    ans1 = ans - 1;
  }
  return ans;
}
void fuck() {
  long long lr = (t - A) / B + 1;
  long long ans1 = solve(t * m);
  if (lr > ans1) {
    cout << ans1 << endl;
  } else
    cout << lr << endl;
}
int main() {
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    if (work(l) > t) {
      printf("-1\n");
      continue;
    }
    fuck();
  }
  return 0;
}
