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