#include <bits/stdc++.h>
using namespace std;
int a, b, n;
long long sum[1100100], s[1100100];
int main() {
  scanf("%d %d %d", &a, &b, &n);
  sum[0] = s[0] = 0;
  long long curr = a;
  for (int i = 1; i < 1100100; i++) {
    sum[i] = sum[i - 1] + curr;
    s[i] = curr;
    curr += b;
  }
  for (int i = 0; i < n; i++) {
    int il, it, im;
    long long l, t, m;
    scanf("%d %d %d", &il, &it, &im);
    l = il;
    t = it;
    m = im;
    int ret =
        min(upper_bound(s, s + 1100100, t) - 1 - s,
            upper_bound(sum, sum + 1100100, t * m + sum[l - 1]) - 1 - sum);
    if (sum[ret] - sum[l - 1] > t * m || s[ret] > t || ret < l)
      printf("-1\n");
    else
      printf("%d\n", ret);
  }
  return 0;
}
