#include <bits/stdc++.h>
using namespace std;
const int sigma_size = 26;
const int N = 100 + 50;
const int MAXN = 100000;
const int inf = 0x3fffffff;
const double eps = 1e-8;
const int mod = 1000000000 + 7;
int A, B, n, L, t, m;
int main() {
  while (~scanf("%d%d%d", &A, &B, &n)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d%d%d", &L, &t, &m);
      int l = L, r = inf, ans = -1;
      while (l <= r) {
        int mid = (l + r) >> 1;
        long long sum = (long long)(mid - L + 1) * (long long)A +
                        (long long)(L + mid - 2) * (long long)(mid - L + 1) /
                            2 * (long long)B -
                        (long long)m * (long long)t;
        if ((long long)A + (long long)B * (long long)(mid - 1) <= t &&
            sum <= 0) {
          ans = mid;
          l = mid + 1;
        } else
          r = mid - 1;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
