#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
long long extended(long long a, long long b, long long &x, long long &y) {
  a = abs(a);
  b = abs(b);
  long long g, x1, y1;
  if (!b) {
    x = 1;
    y = 0;
    g = a;
    return g;
  }
  g = extended(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
  return g;
}
long long modinverse(long long a, long long M) { return bigmod(a, M - 2, M); }
long long bpow(long long p, long long e) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p);
    p = (p * p);
  }
  return ret;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
string convertInt(long long number) {
  if (number == 0) return "0";
  string temp = "";
  string returnvalue = "";
  while (number > 0) {
    temp += number % 10 + 48;
    number /= 10;
  }
  for (int i = 0; i < temp.length(); i++)
    returnvalue += temp[temp.length() - i - 1];
  return returnvalue;
}
long long ncr[1001][1001];
void NCR() {
  for (int i = 1; i <= 1000; i++) {
    ncr[i][i] = 1;
    ncr[i][0] = 1;
    for (int r = 1; r < i; r++) {
      ncr[i][r] = (ncr[i - 1][r] + ncr[i - 1][r - 1]) % 1000000007;
    }
  }
}
long long a, b, n, l, t, m, val;
long long csum[10000005], ar[10000005];
bool chk(int x) {
  if (ar[x] > t) return 0;
  long long cal = csum[x] - csum[l - 1];
  if (cal <= val) return 1;
  return 0;
}
int b_s() {
  int lo, hi, mid;
  val = t * m;
  lo = l, hi = 10000000;
  int ans;
  ans = -1;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (chk(mid)) {
      lo = mid + 1;
      ans = mid;
    } else {
      hi = mid - 1;
    }
  }
  return ans;
}
int main() {
  cin >> a >> b >> n;
  for (int i = 1; i < 10000004; i++) {
    ar[i] = (long long)(i - 1) * b + a;
    csum[i] = csum[i - 1] + ar[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> l >> t >> m;
    cout << b_s() << endl;
  }
  return 0;
}
