#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200009;
long long A, B, n, l, t, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> A >> B >> n;
  while (n--) {
    cin >> l >> t >> m;
    long long a = (l - 1) * B, to = t * m, pr = l;
    if (a + A > t) {
      cout << -1 << "\n";
      continue;
    }
    for (long long j = 31ll; j >= 0ll; j--) {
      long long x = l + (1ll << j);
      long long b = (x - 1) * B;
      if (((b + a) * (b - a + B) / (2 * B)) + (x - pr + 1ll) * A <= to &&
          b + A <= t)
        l += (1ll << j);
    }
    cout << l << "\n";
  }
}
