#include <bits/stdc++.h>
using namespace std;
int A, B, t, m, l;
bool ok(int r) {
  long long sum, sl, rest, sr, impart;
  sl = A + (1ll * l - 1) * 1ll * B;
  sr = A + (1ll * r - 1) * 1ll * B;
  impart = min(m, (r - l + 1));
  if (sr > t) return 0;
  sum = (sl + sr) * (r - l + 1) / 2;
  rest = sum % m;
  sum = sum / m;
  if (rest) sum++;
  if (sum <= t) return 1;
  return 0;
}
int binarySearch(int st, int dr) {
  int med, last = -1;
  while (st <= dr) {
    med = (1ll * st + dr) / 2;
    if (ok(med)) {
      last = med;
      st = med + 1;
    } else
      dr = med - 1;
  }
  return last;
}
int main() {
  int n, i, k;
  scanf("%d%d%d", &A, &B, &n);
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &l, &t, &m);
    k = binarySearch(l, 2000000000);
    printf("%d\n", k);
  }
  return 0;
}
