#include <bits/stdc++.h>
using namespace std;
long long A, B;
long long calc(long long l, long long r) {
  long long ans = (r - l + 1) * (A - B);
  long long r2 = (r * (r + 1)) / 2;
  long long l2 = (l * (l - 1)) / 2;
  ans += B * (r2 - l2);
  return ans;
}
int main() {
  int n;
  cin >> A >> B >> n;
  int i;
  for (i = 0; i < n; ++i) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long h1 = A + (l - 1) * B;
    if (h1 > t) {
      printf("-1\n");
      continue;
    }
    long long temp = ((l - 1) * (A - B)) + B * ((l * (l - 1)) / 2);
    long long temp2 = m * t + temp;
    temp2 = temp2 * 2;
    long long b = 2 * A - B;
    long long d = b * b + 4 * B * temp2;
    double x = sqrt(d);
    x = x - 2 * A + B;
    x /= 2 * B;
    long long maxh2;
    long long maxr = ceil(x);
    maxh2 = A + (maxr - 1) * B;
    long long sum = calc(l, maxr);
    if (maxh2 <= t && sum <= m * t) {
      cout << maxr << "\n";
      continue;
    }
    maxr--;
    maxh2 = A + (maxr - 1) * B;
    sum = calc(l, maxr);
    if (maxh2 <= t && sum <= m * t) {
      cout << maxr << "\n";
      continue;
    }
    maxr--;
    maxh2 = A + (maxr - 1) * B;
    sum = calc(l, maxr);
    if (maxh2 <= t && sum <= m * t) {
      cout << maxr << "\n";
      continue;
    }
    long long r = ceil((t - A) / B) + 1;
    maxh2 = A + (r - 1) * B;
    if (maxh2 <= t) {
      cout << r << "\n";
      continue;
    }
    r--;
    maxh2 = A + (r - 1) * B;
    if (maxh2 <= t) {
      cout << r << "\n";
      continue;
    }
    r--;
    maxh2 = A + (r - 1) * B;
    if (maxh2 <= t) {
      cout << r << "\n";
      continue;
    }
    printf("-1\n");
  }
  return 0;
}
