#include <bits/stdc++.h>
using namespace std;
int n;
long long a, b, t, m;
long long sum[1000100];
void init() {
  sum[0] = 0;
  sum[1] = a;
  for (long long i = 2; i <= 1000000; i = i + 1LL)
    sum[i] = sum[i - 1] + a + (i - 1LL) * b;
}
int main() {
  long long tmp;
  scanf("%I64d%I64d%I64d", &a, &b, &n);
  init();
  while (n--) {
    scanf("%I64d%I64d%I64d", &tmp, &t, &m);
    long long left = tmp, right = 1000000;
    while (left < right) {
      long long mid = left + (right - left + 1LL) / 2LL;
      if ((a + (mid - 1LL) * b) <= t && (sum[mid] - sum[tmp - 1]) <= t * m)
        left = mid;
      else
        right = mid - 1LL;
    }
    if ((a + (left - 1LL) * b) <= t && (sum[left] - sum[tmp - 1]) <= t * m)
      printf("%I64d\n", left);
    else
      puts("-1");
  }
  return 0;
}
