#include <bits/stdc++.h>
using namespace std;
long long n, a, b, l, m, t;
long long sum_till_x(long long x) {
  return (a - b) * x + b * (((x + 1) * x) / 2);
}
long long ch(long long md) {
  if (a + (l + md - 1) * b > t) return 0;
  long long z = min(m, md + 1) * t;
  long long y = sum_till_x(l + md) - sum_till_x(l - 1);
  return z >= y;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin >> a >> b >> n;
  while (n--) {
    cin >> l >> t >> m;
    long long hi = t + t - 1, lo = 0, md = (lo + hi) / 2;
    while (hi - lo > 1) {
      if (ch(md))
        lo = md;
      else
        hi = md;
      md = (hi + lo) / 2;
    }
    if (ch(lo))
      cout << l + lo << endl;
    else if (ch(hi))
      cout << l + hi << endl;
    else
      cout << -1 << endl;
  }
}
