#include <bits/stdc++.h>
using namespace std;
long long get_sum(long long l, long long r, long long a, long long b) {
  long long len = r - l + 1;
  long long st = a + (l - 1) * b;
  long long ed = a + (r - 1) * b;
  return len * (ed + st) / 2;
}
int main() {
  int a, b, n;
  ios::sync_with_stdio(false);
  cin >> a >> b >> n;
  while (n--) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long lt = l, rt = t, mid, ans = -1;
    while (lt <= rt) {
      mid = (lt + rt) >> 1;
      if (a + (mid - 1) * b > t) {
        rt = mid - 1;
        continue;
      }
      if (get_sum(l, mid, a, b) <= m * t)
        ans = mid, lt = mid + 1;
      else
        rt = mid - 1;
    }
    cout << ans << endl;
  }
  return 0;
}
