#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e6 + 7;
const int INF = (int)1e9 + 7;
long long f, s, n;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> f >> s >> n;
  for (int i = 1; i <= n; i++) {
    long long low, T, m;
    cin >> low >> T >> m;
    long long st = low;
    long long F = f + s * (low - 1);
    long long high = MAXN * 2;
    if (F > T) {
      cout << "-1\n";
      continue;
    }
    while (high - low > 1) {
      long long mid = (low + high) / 2;
      long long S = f + s * (mid - 1);
      long long SUM = (F + S) * (mid - st + 1) / 2;
      if ((SUM + m - 1) / m <= T && S <= T)
        low = mid;
      else
        high = mid;
    }
    cout << low << "\n";
  }
  return 0;
}
