#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long A, B;
bool check(long long L, long long R, long long m, long long t) {
  long long sum = (R - L + 1) * A + (L + R - 2) * (R - L + 1) / 2 * B;
  if (sum <= m * t && A + B * (R - 1) <= t) return true;
  return false;
}
int main() {
  int n;
  while (scanf("%d%I64d%I64d", &A, &B, &n) != EOF) {
    for (int i = 0; i < n; ++i) {
      long long l, t, m;
      scanf("%I64d%I64d%I64d", &l, &t, &m);
      int L = l, R = l + t, ans = -1;
      while (L <= R) {
        int mid = (L + R) >> 1;
        if (check(l, mid, m, t))
          ans = mid, L = mid + 1;
        else
          R = mid - 1;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
