#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b, i, l, t, m, val, s1, s2, low, mid, high, x, y, z, p, q,
      ans;
  while (scanf("%lld%lld%lld", &a, &b, &n) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%lld%lld%lld", &l, &t, &m);
      val = t * m;
      x = ((2 * a + (l - 2) * b) * (l - 1)) / 2;
      q = a + (l - 1) * b;
      if (q > t) {
        printf("-1\n");
        continue;
      }
      low = l;
      high = 1000000;
      while (low <= high) {
        mid = (low + high) / 2;
        y = ((2 * a + (mid - 1) * b) * (mid)) / 2;
        p = a + (mid - 1) * b;
        z = y - x;
        if ((z <= val) && (p <= t)) {
          ans = mid;
          low = mid + 1;
        } else
          high = mid - 1;
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
