#include <bits/stdc++.h>
using namespace std;
long long a, b, n, l, t, m;
;
long long getnum(long long i) { return a + (i - 1) * b; }
long long sum(long long r) { return (getnum(l) + getnum(r)) * (r - l + 1) / 2; }
int main() {
  long long le, ri, mid;
  scanf("%I64d%I64d%I64d", &a, &b, &n);
  while (n--) {
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    long long lnum = getnum(l);
    if (lnum > t)
      printf("-1\n");
    else {
      le = l;
      ri = (t - a) / b + 1;
      while (le <= ri) {
        mid = (le + ri) / 2;
        if (sum(mid) > m * t)
          ri = mid - 1;
        else
          le = mid + 1;
      }
      printf("%I64d\n", le - 1);
    }
  }
  return 0;
}
