#include <bits/stdc++.h>
using namespace std;
long long int a, b, l, m, t, n, x, y, mid, s, f;
int main() {
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> t >> m;
    x = (t - a) / b + 1;
    if (x < l) {
      cout << -1 << endl;
      continue;
    }
    s = 0;
    f = x - l + 1;
    while (f - s > 1) {
      mid = (s + f) / 2;
      if (a * (mid + 1) + (mid + 1) * (l + l + mid - 2) / 2 * b <= m * t)
        s = mid;
      else
        f = mid;
    }
    cout << l + s << endl;
  }
  return 0;
}
