#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
long long a, b, st;
long long call(long long n) {
  long long temp = 2 * st + (n - 1) * b;
  temp = temp * n;
  return temp / 2;
}
long long higt(long long n) { return a + (n - 1) * b; }
int main() {
  long long n, l, m, t;
  scanf("%lld %lld", &a, &b);
  scanf("%lld", &n);
  while (n--) {
    scanf("%lld %lld", &l, &t);
    scanf("%lld", &m);
    long long temp = higt(l);
    if (temp > t) {
      printf("-1\n");
      continue;
    }
    long long all = m * t;
    long long lo = l, hg = l + max(m, t) + 7;
    st = higt(l);
    while (lo <= hg) {
      long long mid = (lo + hg) / 2;
      temp = call(mid - l + 1);
      if (higt(mid) <= t and temp <= all)
        lo = mid + 1;
      else
        hg = mid - 1;
    }
    printf("%lld\n", lo - 1);
  }
  return 0;
}
