#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l, t, m;
  long long a, b, c;
  long long left, mid, right;
  cin >> a >> b >> c;
  for (int i = 0; i < c; ++i) {
    bool fail = false;
    cin >> l >> t >> m;
    left = l;
    right = (t - a) / b + 1;
    while (1) {
      mid = left + (right - left + 1) / 2;
      if ((mid - l + 1) * (a + (l - 1) * b + a + (mid - 1) * b) / 2 <= t * m) {
        left = mid;
      } else {
        right = mid - 1;
      }
      if (right < left) {
        fail = true;
        break;
      }
      if (mid == left && left == right) break;
    }
    if (!fail)
      cout << mid;
    else
      cout << -1;
    cout << endl;
  }
}
