#include <bits/stdc++.h>
using namespace std;
long long a, b, n, l, t, m, sum = 0;
int main() {
  scanf("%lld", &a);
  scanf("%lld", &b);
  scanf("%lld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &l);
    scanf("%lld", &t);
    scanf("%lld", &m);
    long long end = (t - a) / b + 1;
    if (end < l) {
      cout << "-1\n";
    } else {
      sum = t * m;
      long long ft = a + (l - 1) * b;
      long long sterm = (b - 2 * ft);
      long long sq = (long long)sqrt(sterm * sterm + 8 * b * sum);
      long long r1 = (sterm + sq) / (2 * b);
      long long r2 = (sterm - sq) / (2 * b);
      long long root = max(r1, r2);
      long long ans = l + root - 1;
      printf("%lld\n", min(ans, end));
    }
  }
  return 0;
}
