#include <bits/stdc++.h>
using namespace std;
long long int a, b, n;
long long int binsearch(long long int x, long long int start,
                        long long int sz) {
  long long int lbound = start, ubound = sz, mid = (lbound + ubound) / 2,
                comp = 0, te = 0;
  while (lbound <= ubound) {
    mid = (lbound + ubound) / 2;
    comp = ((mid - start + 1) * (2 * a + (mid + start - 2) * b)) / 2;
    te = (((mid + 1) - start + 1) * (2 * a + ((mid + 1) + start - 2) * b)) / 2;
    if (comp > x)
      ubound = mid - 1;
    else if (comp < x) {
      if (te > x || mid + 1 > sz)
        return mid;
      else
        lbound = mid + 1;
    } else if (comp == x)
      return mid;
  }
  return -1;
}
int main() {
  cin >> a >> b >> n;
  while (n-- > 0) {
    long long int l, t, m;
    cin >> l >> t >> m;
    if ((a + (l - 1) * b) > t) {
      cout << -1 << endl;
      continue;
    }
    int x = (t - a + b) / b;
    long long int ans = binsearch(t * m, l, x);
    cout << ans << endl;
  }
  return 0;
}
