#include <bits/stdc++.h>
using namespace std;
long long a[2000005], s[2000005] = {0};
long long n, i, t, l, m, ql, qr, mid, A, B;
long long findAns() {
  while (ql + 1 < qr) {
    mid = (qr + ql) / 2;
    long long tmp = max(a[mid], (s[mid] - s[l - 1]) % m == 0
                                    ? (s[mid] - s[l - 1]) / m
                                    : ((s[mid] - s[l - 1]) / m + 1));
    if (tmp <= t)
      ql = mid;
    else
      qr = mid;
  }
  return ql;
}
int main() {
  scanf("%I64d%I64d%I64d", &A, &B, &n);
  a[1] = s[1] = A;
  for (i = 2; i <= 2000000; i++) {
    a[i] = a[i - 1] + B;
    s[i] = s[i - 1] + a[i];
  }
  while (n--) {
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    ql = l;
    qr = 2000000;
    if (a[ql] > t) {
      printf("-1\n");
      continue;
    }
    printf("%I64d\n", findAns());
  }
  return 0;
}
