#include <bits/stdc++.h>
using namespace std;
unsigned long long arr[2 * (int)1e6 + 10], sum[2 * (int)1e6 + 10] = {0};
int main() {
  unsigned long long a, b, n;
  scanf("%I64d%I64d%I64d", &a, &b, &n);
  for (int i = 1; i <= 2 * 1e6; i++)
    arr[i] = a + (i - 1) * b, sum[i] = arr[i] + sum[i - 1];
  while (n--) {
    unsigned long long l, t, m;
    cin >> l >> t >> m;
    int lo = l, hi = 2 * 1e6;
    while (hi > lo) {
      if (hi == lo + 1) {
        if (arr[hi] <= t && sum[hi] - sum[l - 1] <= m * t) {
          hi = lo = lo + 1;
          break;
        }
        hi = lo;
        break;
      }
      if (arr[(lo + hi) / 2] <= t && sum[(lo + hi) / 2] - sum[l - 1] <= m * t)
        lo = (lo + hi) / 2;
      else
        hi = (lo + hi) / 2 - 1;
    }
    if (arr[(lo + hi) / 2] <= t && sum[(lo + hi) / 2] - sum[l - 1] <= t * m &&
        (lo + hi) / 2 >= l)
      printf("%d\n", (lo + hi) / 2);
    else
      puts("-1");
  }
}
