#include <bits/stdc++.h>
using namespace std;
long long s[1000005], sum[1000005];
long long l, t, m;
bool OK(int ind) {
  if (s[ind] <= t && sum[ind] - sum[l - 1] <= m * t) return true;
  return false;
}
int main() {
  long long a, b;
  int n, i, low, high, mid, ans;
  scanf("%lld%lld%d", &a, &b, &n);
  for (i = 1; i <= 1000000; i++) {
    s[i] = a + (i - 1) * b;
    sum[i] = sum[i - 1] + s[i];
  }
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &l, &t, &m);
    low = l;
    high = 1000000;
    ans = -1;
    while (low <= high) {
      mid = (low + high) >> 1;
      if (OK(mid)) {
        ans = mid;
        low = mid + 1;
      } else
        high = mid - 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}
