#include <bits/stdc++.h>
using namespace std;
int n;
long long A, B;
long long l, t, m;
long long L, R, mid;
long long f(long long x) { return A + (x - 1LL) * B; }
long long S(long long a, long long b, long long k) { return (a + b) * k / 2LL; }
int main() {
  scanf("%I64d%I64d%d", &A, &B, &n);
  while (n--) {
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    if (f(l) > t) {
      puts("-1");
      continue;
    }
    L = 0;
    R = 2000000;
    while (L < R) {
      bool ok = true;
      mid = (L + R + 1) >> 1;
      long long r = l + mid;
      if (f(r) > t) ok = false;
      if (S(f(l), f(r), r - l + 1) > m * t) ok = false;
      if (ok)
        L = mid;
      else
        R = mid - 1;
    }
    printf("%d\n", l + L);
  }
  return 0;
}
