#include <bits/stdc++.h>
using namespace std;
const int md = 2000200;
int a, b, n, l, m, t;
unsigned long long a1[2000200];
unsigned long long ss[2000200];
int main() {
  scanf("%d", &a), scanf("%d", &b), scanf("%d", &n);
  ss[0] = 0ll;
  for (int i = 1; i <= 2000195; i++) {
    unsigned long long p = a + 1ll * (i - 1) * b;
    a1[i] = p;
    ss[i] = ss[i - 1] + 1ll * p;
  }
  while (n--) {
    scanf("%d", &l), scanf("%d", &t), scanf("%d", &m);
    int sp = lower_bound(ss, ss + md, ss[l - 1] + 1ll * m * t + 1) - ss - 1;
    int sp1 = lower_bound(a1, a1 + md, 1ll * t + 1) - a1 - 1;
    sp = min(sp, sp1);
    if (sp < l) {
      puts("-1");
      continue;
    }
    printf("%d\n", sp);
  }
  return 0;
}
