#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e6 + 1;
const int INF = 1e9 + 7;
long long a, b, n;
long long h[MXN];
int get(long long l, long long t, long long m) {
  if (h[l] - h[l - 1] > t) return -1;
  int hi = MXN, lo = l;
  while (hi - lo > 1) {
    int mid = (lo + hi) / 2;
    if (h[mid] - h[mid - 1] <= t &&
        h[mid] - h[l - 1] <= t * min(mid - l + 1LL, m))
      lo = mid;
    else
      hi = mid;
  }
  return lo;
}
int main() {
  scanf("%d%d%d", &a, &b, &n);
  for (int i = 1; i < MXN; i++) h[i] = h[i - 1] + a + (i - 1) * 1LL * b;
  while (n--) {
    int l, t, m;
    scanf("%d%d%d", &l, &t, &m);
    printf("%d\n", get(l * 1LL, t * 1LL, m * 1LL));
  }
  return 0;
}
