#include <bits/stdc++.h>
using namespace std;
long long A, B;
long long iter, wide, lllft, lef;
bool isOk(long long rig) {
  long long total =
      (A + B * (lllft - 1) + A + B * (rig - 1)) * (rig + 1 - lllft) / 2;
  long long maxx = A + B * (rig - 1);
  return total <= iter * wide && maxx <= iter;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  while (cin >> A) {
    cin >> B >> n;
    while (n--) {
      long long rig, step;
      cin >> lllft >> iter >> wide;
      rig = lllft - 1;
      step = iter;
      while (step) {
        if (isOk(rig + step)) {
          rig += step;
        } else
          step /= 2;
      }
      if (rig < lllft) rig = -1;
      cout << rig << "\n";
    }
  }
}
