#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
inline long long read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long A, B, q, t, m, l;
long long ans(long long x) { return A + (x - 1) * B; }
long long sum(long long l, long long r) {
  long long x1 = A + (l - 1) * B, x2 = A + (r - 1) * B;
  return 1ll * (x1 + x2) * (r - l + 1) / 2;
}
int main() {
  scanf("%d%d%d", &A, &B, &q);
  while (q--) {
    int l, t, m;
    scanf("%d%d%d", &l, &t, &m);
    int lef = l, rig = inf, mid;
    while (lef <= rig) {
      mid = lef + rig >> 1;
      if (ans(mid) <= t && sum(l, mid) <= 1ll * t * m)
        lef = mid + 1;
      else
        rig = mid - 1;
    }
    if (rig == l - 1)
      printf("-1\n");
    else
      printf("%d\n", rig);
  }
  return 0;
}
