#include <bits/stdc++.h>
using namespace std;
char s[1000010], p[1000010];
long long a, b, n, l, t, m;
bool verif(long long x, long long sum) {
  long long crtSum =
      (x - l + 1) * a + (x - 1) * x / 2 * b - (l - 1) * (l - 2) / 2 * b;
  return (crtSum <= t * m && a + (x - 1) * b <= t);
}
int main() {
  cin >> a >> b >> n;
  while (n--) {
    cin >> l >> t >> m;
    if (a + b * (l - 1) > t) {
      cout << -1 << "\n";
      continue;
    }
    long long left = l, right = l + t;
    while (left <= right) {
      int middle = (left + right) / 2;
      if (verif(middle, 1LL * t * m))
        left = middle + 1;
      else
        right = middle - 1;
    }
    cout << right << "\n";
  }
  return 0;
}
