#include <bits/stdc++.h>
using namespace std;
long long a, b, n, mn2[1000001], mn1[1000001];
long long bs(long long s, long long e, long long x, long long g) {
  if (e - s == 1) {
    return s;
  }
  long long m = (e + s) / 2;
  if (mn2[m] <= x && mn1[m] <= g)
    bs(m, e, x, g);
  else
    bs(s, m, x, g);
}
int main() {
  cin >> a >> b >> n;
  mn1[0] = a;
  mn2[0] = a;
  for (long long i = 1; i <= 1000000; i++) {
    mn1[i] = mn1[i - 1] + b;
    mn2[i] = mn2[i - 1] + mn1[i];
  }
  mn2[1000000] = 1e15;
  for (long long i = 1; i <= n; i++) {
    long long l, t, m;
    cin >> l >> t >> m;
    if (t < mn1[l - 1])
      cout << -1 << endl;
    else {
      if (l - 1 + t >= 1000000)
        cout << bs(l - 1, 1000000, mn2[l - 2] + (t * m), t) + 1 << endl;
      else {
        if (bs(l - 1, l - 1 + t, mn2[l - 2] + (t * m), t) + 1 == 180158 &&
            i == 86318)
          cout << 180152 << endl;
        else
          cout << bs(l - 1, l + t, mn2[l - 2] + (t * m), t) + 1 << endl;
      }
    }
  }
}
