#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  unsigned long long a, b, n;
  cin >> a >> b >> n;
  for (unsigned long long i = 0; i < n; ++i) {
    unsigned long long l, t, m;
    cin >> l >> t >> m;
    unsigned long long lh = a + (l - 1) * b;
    if (lh > t)
      cout << -1 << '\n';
    else {
      unsigned long long tm = t * m;
      double ka = b, kb = 2. * a - b,
             kc = 2. * a - 2. * tm - 2. * l * a + 3. * b * l - 2. * b -
                  (double)b * l * l,
             d = kb * kb - 4. * ka * kc;
      if (d < 0)
        cout << -1 << '\n';
      else {
        double qr = (-kb + sqrt(d)) / (2. * ka);
        unsigned long long rr = qr, rrl = l, rrr = qr, rrm = (rrl + rrr) / 2;
        while (rrr > rrl && rrl < rrm) {
          unsigned long long ra = a + (rrm - 1) * b;
          if (ra > t)
            rrr = rrm - 1;
          else
            rrl = rrm;
          rrm = (rrl + rrr) / 2;
        }
        rr = rrl;
        if (a + rr * b <= t && rr < (unsigned long long)qr) ++rr;
        if (rr == 0)
          cout << -1 << '\n';
        else
          cout << rr << '\n';
      }
    }
  }
  return 0;
}
