#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 8;
inline bool check(const long long &a, const long long &b, long long &suml,
                  const long long &t, const long long &m,
                  const long long &mid) {
  if (a + (mid - 1) * b > t) return false;
  if ((2 * a + (mid - 1) * b) * mid / 2 - suml > t * m)
    return false;
  else
    return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b, n, l, t, m, r, suml;
  cin >> a >> b >> n;
  while (n--) {
    r = -1;
    cin >> l >> t >> m;
    suml = (2 * a + ((l - 1) - 1) * b) * (l - 1) / 2;
    long long x = l, y = (t - a) / b + 1 + 1, mid;
    while (x + 1 < y) {
      mid = (x + y) >> 1;
      if (check(a, b, suml, t, m, mid))
        x = mid;
      else
        y = mid;
    }
    if (check(a, b, suml, t, m, y))
      r = y;
    else if (check(a, b, suml, t, m, x))
      r = x;
    else
      r = -1;
    if (n)
      cout << r << "\n";
    else
      cout << r << endl;
  }
  return 0;
}
