#include <bits/stdc++.h>
using namespace std;
long long int A, B, a, i, j, l[100001], t[100001], m[100001], s[10000001],
    d[10000001];
int main() {
  cin >> A >> B >> a;
  for (i = 1; i <= a; i++) cin >> l[i] >> t[i] >> m[i];
  for (i = 1; i <= 5000000; i++) {
    s[i] = A + (i - 1) * B;
    d[i] = d[i - 1] + s[i];
  }
  for (i = 1; i <= a; i++) {
    long long int l1 = l[i], r1 = 5000000, m1;
    while (l1 < r1) {
      m1 = (l1 + r1) / 2;
      if (s[m1] <= t[i] &&
          (d[m1 + 1] - d[l[i] - 1] + t[i] - 1) / t[i] <= m[i] &&
          s[m1 + 1] <= t[i])
        l1 = m1 + 1;
      else
        r1 = m1;
    }
    if (s[l[i]] > t[i])
      cout << "-1\n";
    else
      cout << l1 << endl;
  }
}
