#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")
long long sum[2000200];
int main() {
  int A, B, N;
  scanf("%d %d %d", &A, &B, &N);
  sum[1] = A;
  for (int i = 2; i < 2000200; i++) sum[i] = sum[i - 1] + (long long)B;
  for (int i = 1; i < 2000200; i++) sum[i] += sum[i - 1];
  for (int test = 0; test < N; test++) {
    int L, t, m;
    scanf("%d %d %d", &L, &t, &m);
    long long first = sum[L] - sum[L - 1];
    int l = L - 1, r = 2000000;
    while (l < r) {
      int av = (l + r + 1) / 2;
      long long second = sum[av] - sum[av - 1];
      if (second > t) {
        r = av - 1;
        continue;
      }
      long long s = sum[av] - sum[L - 1];
      int cnt = min(m, av - L + 1);
      if (s > (long long)t * (long long)(cnt)) {
        r = av - 1;
        continue;
      }
      l = av;
    }
    if (l >= L) {
      printf("%d\n", l);
    } else
      printf("-1\n");
  }
  return 0;
}
