#include <bits/stdc++.h>
using namespace std;
long long arr[2000005];
long long cum[2000005];
long long x, l, t;
long long bs() {
  long long s = l, e = 1e6, mid;
  while (s < e) {
    mid = (s + e + 1) / 2;
    if (cum[mid] - cum[l - 1] <= x && arr[mid] <= t)
      s = mid;
    else
      e = mid - 1;
  }
  return s;
}
int main() {
  long long a, b, n, m, tmp;
  cin >> a >> b >> n;
  for (int i = 1; i <= 1e6; i++) arr[i] = (i - 1) * b + a;
  for (int i = 1; i <= 1e6; i++) cum[i] = arr[i] + cum[i - 1];
  for (int i = 0; i < n; i++) {
    cin >> l >> t >> m;
    x = t * m;
    tmp = bs();
    if (cum[tmp] - cum[l - 1] <= x && arr[tmp] <= t)
      cout << tmp << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
