#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long a, b, n, t, l, m;
  cin >> a >> b >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> l >> t >> m;
    cout << endl
         << ((a + b * (l - 1) > t)
                 ? -1
                 : min((t - a) / b + 1,
                       (long long)(l +
                                   (sqrt((2 * a - 3 * b + 2 * l * b) *
                                             (2 * a - 3 * b + 2 * l * b) +
                                         (8 * b * m * t)) -
                                    (2 * a - 3 * b + 2 * l * b)) /
                                       2 / b -
                                   1)));
  }
}
