#include <bits/stdc++.h>
using namespace std;
long long A, B, n;
bool judge(long long s, long long t, long long m, long long time) {
  long long an = A + B * (t - 1), a1 = A + B * (s - 1), n = t - s + 1;
  long long sum = (a1 + an) * n / 2;
  return max(an, (sum + m - 1) / m) <= time;
}
int main() {
  scanf("%I64d%I64d%I64d", &A, &B, &n);
  while (n--) {
    long long L, t, m;
    scanf("%I64d%I64d%I64d", &L, &t, &m);
    long long low = A + B * (L - 1);
    if (t < low)
      puts("-1");
    else {
      long long l = L, r = 1e9;
      while (l <= r) {
        long long mid = (l + r) >> 1;
        if (judge(L, mid, m, t))
          l = mid + 1;
        else
          r = mid - 1;
      }
      printf("%I64d\n", r);
    }
  }
  return 0;
}
