#include <bits/stdc++.h>
using namespace std;
long long need[2000001];
bool possible(long long fidx, long long tidx, long long first, long long change,
              long long limit, long long dist) {
  bool ans = false;
  long long startval = first + (fidx - 1) * change;
  long long endval = first + (tidx - 1) * change;
  if (endval > limit) {
    return false;
  }
  long long total = ((tidx - fidx + 1) * (startval + endval)) / 2;
  long long xx = limit * dist;
  if (total <= xx) {
    return true;
  }
  return false;
}
int main(void) {
  int t = 1;
  while (t--) {
    long long A, B, n;
    cin >> A >> B >> n;
    for (int i = 1; i <= n; i++) {
      long long l, t, m;
      scanf("%I64d", &l);
      scanf("%I64d", &t);
      scanf("%I64d", &m);
      long long low = l;
      long long high = l + t;
      long long ans = -1;
      while (low <= high) {
        long long mid = (low + high) / 2;
        if (possible(l, mid, A, B, t, m)) {
          ans = max(ans, mid);
          low = mid + 1;
        } else {
          high = mid - 1;
        }
      }
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
