#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a, b, n, l, t, m;
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> t >> m;
    long long cur = a + (l - 1) * b;
    if (cur > t) {
      cout << "-1\n";
      continue;
    }
    long long can_go = t;
    long long r = l + ((t - cur) / b);
    long long s =
        ((r - 1) * (a + a + (r - 2) * b)) - ((l - 1) * (a + a + (l - 2) * b));
    s /= 2;
    if (s <= (m - 1) * t) {
      cout << r << endl;
    } else {
      long long ans = 0;
      long long lo = l, hi = r - 1;
      while (lo <= hi) {
        long long mid = (lo + hi) / 2;
        s = ((mid) * (a + a + (mid - 1) * b)) -
            ((l - 1) * (a + a + (l - 2) * b));
        s /= 2;
        if (s <= m * t) {
          ans = max(mid, ans);
          lo = mid + 1;
        } else
          hi = mid - 1;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
