#include <bits/stdc++.h>
using namespace std;
long long n, A, B;
long long s(long long i, long long b) {
  long long len = i - b + 1;
  return len * A + B * (((b + i - 2) * len) / 2);
}
bool check(long long idx, long long beg, long long m, long long t) {
  long long d = min(idx - beg + 1, m);
  long long con = (A + B * (idx - 1)) <= t;
  return (s(idx, beg) <= d * t) && con;
}
long long Solve(long long t, long long m, long long l) {
  long long low = l, high = 1e8, mid = (low + high) / 2;
  while (low < high) {
    if (low == high) break;
    if (low + 1 == high) {
      if (check(high, l, m, t)) {
        mid = high;
        break;
      } else if (check(low, l, m, t)) {
        mid = low;
        break;
      } else {
        mid = -1;
        break;
      }
    }
    if (check(mid, l, m, t)) {
      low = mid;
      mid = (low + high) / 2;
    } else {
      high = mid;
      mid = (low + high) / 2;
    }
  }
  return mid;
}
int main() {
  ios::sync_with_stdio(0), cout.tie(0);
  cin >> A >> B >> n;
  long long l, t, m;
  while (n--) {
    cin >> l >> t >> m;
    cout << Solve(t, m, l) << "\n";
  }
}
