#include <bits/stdc++.h>
static const int N = 200;
static const int M = 1000010;
static const int LEN = 210;
static const int MAX = 0x7fffffff;
static const int GMAX = 0x3f3f3f3f;
static const long long LGMAX = 0x3f3f3f3f3f3f3f3f;
static const int MIN = ~MAX;
static const double EPS = 1e-9;
static const long long BASE = 1000000007;
static const int CH = 27;
long long arr[M];
void solve(long long a, long long b, int l, int t, int m) {
  long long from_num = a + (l - 1) * b;
  if (from_num > (long long)t) {
    printf("-1\n");
    return;
  }
  int r = 1000001;
  int mid, ans;
  int from = l;
  long long tmp;
  while (r >= l) {
    mid = (l + r) / 2;
    bool left = false;
    tmp = ((long long)(mid - from)) * b + from_num;
    if ((long long)t < tmp) {
      left = true;
    }
    long long right_num = from_num + ((long long)(mid - from)) * b;
    tmp = (from_num + right_num) * ((long long)(mid - from + 1)) / 2LL;
    if ((long long)t * (long long)m < tmp) {
      left = true;
    }
    if (!left) {
      ans = mid + 1;
      l = mid + 1;
    } else {
      ans = mid;
      r = mid - 1;
    }
  }
  printf("%d\n", ans - 1);
}
int main() {
  0;
  0;
  long long a, b;
  int n;
  while (scanf("%I64d %I64d %d", &a, &b, &n) != EOF) {
    for (int i = 0; i < n; ++i) {
      int l, t, m;
      scanf("%d %d %d", &l, &t, &m);
      solve(a, b, l, t, m);
    }
  }
  return 0;
}
