#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n;
  scanf("%d%d%d", &a, &b, &n);
  for (int i = 1; i <= n; i++) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long sum1;
    if (l == 1)
      sum1 = 0;
    else
      sum1 = (l - 1) * (2 * a + (l - 2) * b) / 2;
    long long le = l, ri = 100000000;
    long long mid;
    long long flag = -1;
    while (le < ri) {
      mid = (le + ri) / 2;
      if (a + b * (mid - 1) <= t &&
          (mid) * (a * 2 + b * (mid - 1)) / 2 - sum1 <= t * m) {
        le = mid + 1;
        flag = max(flag, mid);
      } else
        ri = mid;
    }
    cout << flag << endl;
  }
  return 0;
}
