#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 100007;
const int inf = 1e9 + 10;
long long A, B, n;
long long l, t, m;
long long height(long long x) { return A + (x - 1) * B; }
bool check(int x) {
  if (height(x) > t) return false;
  long long get = t * min(m, x - l + 1);
  long long need = (height(l) + height(x)) * (x - l + 1) / 2;
  if (get >= need)
    return true;
  else
    return false;
}
int MAIN() {
  scanf("%I64d%I64d%I64d", &A, &B, &n);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d%I64d%I64d", &l, &t, &m);
    if (height(l) > t) {
      printf("-1\n");
      continue;
    }
    int lb = l, rb = (t - A) / B + 1;
    while (height(rb) < t) ++rb;
    ++rb;
    while (rb - lb > 1) {
      int mid = (lb + rb) / 2;
      if (check(mid))
        lb = mid;
      else
        rb = mid;
    }
    printf("%d\n", lb);
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  int ret = MAIN();
  return ret;
}
