#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int main() {
  long long A, B, n, l, t, m;
  cin >> A >> B >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> l >> t >> m;
    if (A + (l - 1) * B > t)
      cout << "-1" << endl;
    else {
      long long min = l;
      long long max = l;
      while (A + (max - 1) * B <= t &
             (max - l + 1) * A + (max - l + 1) * (l - 1 + max - 1) * B / 2 <=
                 m * t)
        max = max * 2;
      while (max - min > 0) {
        long long c = (min + max) / 2 + 1;
        if (A + (c - 1) * B <= t &
            (c - l + 1) * A + (c - l + 1) * (l - 1 + c - 1) * B / 2 <= m * t)
          min = c;
        else
          max = c - 1;
      };
      cout << min << endl;
    }
  }
  return 0;
}
