#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
const int N = 200000;
long long a, b;
long long l, t, m, n;
long long f(long long l, long long r) {
  long long p = a + b * (r - 1);
  if (p > t) return 0;
  if (t * m < (2 * a + b * (r + l - 2)) * (r - l + 1) / 2) return 0;
  return 1;
}
int main() {
  cin >> a >> b >> n;
  for (int i = 0; i < n; ++i) {
    cin >> l >> t >> m;
    long long lef = l, rig = 1e9, mid, ans = -1;
    while (lef <= rig) {
      mid = (lef + rig) >> 1;
      if (f(l, mid)) {
        ans = mid;
        lef = mid + 1;
      } else
        rig = mid - 1;
    }
    printf("%lld\n", ans);
  }
}
