#include <bits/stdc++.h>
using namespace std;
int main() {
  long long A, B, n;
  cin >> A >> B >> n;
  int i;
  for (i = 0; i < n; ++i) {
    long long l, t, m;
    cin >> l >> t >> m;
    long long maxr = ((t - A) / B) + 1;
    long long mid, left, right;
    left = l;
    right = maxr;
    long long ans = -1;
    long long total = m * t;
    long long lh = A + (l - 1) * B;
    while (left <= right) {
      mid = (left + right) / 2;
      long long midh = A + (mid - 1) * B;
      long long sum = (((double)(mid - l + 1)) / 2) * (lh + midh);
      long long sump1 = (((double)(mid + 1 - l + 1)) / 2) * (lh + A + mid * B);
      if (sum == total || mid == right) {
        ans = mid;
        break;
      } else if (sum < total && sump1 > total) {
        ans = mid;
        break;
      } else if (sum < total)
        left = mid + 1;
      else
        right = mid - 1;
    }
    if (ans == -1)
      printf("%d\n", -1);
    else
      printf("%d\n", ans);
  }
  return 0;
}
