#include <bits/stdc++.h>
long long A, B, q;
int main() {
  for (scanf("%I64d%I64d%I64d", &A, &B, &q); q--;) {
    if (q == 0) q = q;
    long long l, L, t, m;
    scanf("%I64d%I64d%I64d", &L, &t, &m);
    long long r, M, res = -1;
    l = L, r = ((t) > (m) ? (t) : (m)) + l + 100;
    while (l <= r) {
      M = (l + r) / 2;
      if (A + (M - 1) * B <= t &&
          A * (M - L + 1) + ((M - 1) * M / 2 - (L - 2) * (L - 1) / 2) * B <=
              m * t)
        l = M + 1, res = ((res) > (M) ? (res) : (M));
      else
        r = M - 1;
    }
    printf("%I64d\n", res);
  }
}
