#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
long long A, B;
int n;
int L, t, m;
bool judge(int r) {
  long long s1 = A + (L - 1) * B, s2 = A + (r - 1) * B;
  long long sum = ((r - L + 1) * (s1 + s2)) / 2;
  long long x = max(s2, (sum + m - 1) / m);
  return x <= t;
}
int BS(int l, int r) {
  if (r - l <= 1) {
    if (judge(r)) return r;
    if (judge(l)) return l;
    return -1;
  }
  int m = (l + r) / 2;
  if (judge(m)) return BS(m, r);
  return BS(l, m - 1);
}
int main() {
  cin >> A >> B >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &L, &t, &m);
    printf("%d\n", BS(L, L + 2000000));
  }
  return 0;
}
