Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs.

<image>

Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is si = A + (i - 1) × B.

For a given m, let's define an m-bite operation as decreasing the height of at most m distinct not eaten Karafses by 1. Karafs is considered as eaten when its height becomes zero.

Now SaDDas asks you n queries. In each query he gives you numbers l, t and m and you should find the largest number r such that l ≤ r and sequence sl, sl + 1, ..., sr can be eaten by performing m-bite no more than t times or print -1 if there is no such number r.

Input

The first line of input contains three integers A, B and n (1 ≤ A, B ≤ 106, 1 ≤ n ≤ 105).

Next n lines contain information about queries. i-th line contains integers l, t, m (1 ≤ l, t, m ≤ 106) for i-th query.

Output

For each query, print its answer in a single line.

Examples

Input

2 1 4
1 5 3
3 3 10
7 10 2
6 4 8


Output

4
-1
8
-1


Input

1 5 2
1 5 10
2 7 4


Output

1
2
import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import java.math.*;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Input in = new Input(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}
}

class Task {
	static final long MOD = 1000000007;
	int[] primes;

	public void solve(int testNumber, Input in, PrintWriter out) {
		long A = in.nextLong();
		long B = in.nextLong();
		int n = in.nextInt();
		for (int i = 0; i < n; i++) {
			long l = in.nextLong();
			long t = in.nextLong();
			long m = in.nextLong();

			if (A + (l - 1) * B > t) {
				out.println(-1);
			} else {
				long left = l;
				long right = l + 1000000;
				while (left < right) {
					long mid = (left + right + 1) >> 1;
					long sum = (mid * (2 * A + (mid - 1) * B) - (l - 1)
							* (2 * A + (l - 2) * B)) / 2;
					if (t >= A + (mid - 1) * B && sum <= t * m) {
						left = mid;
					} else {
						right = mid - 1;
					}
				}
				out.println(left);
			}
		}

	}

	private boolean isQuare(int[][] m) {
		long[] dist = new long[6];
		int index = 0;
		for (int i = 0; i < 4; i++) {
			for (int j = i + 1; j < 4; j++) {
				dist[index++] = dist(m[i][0], m[i][1], m[j][0], m[j][1]);
			}
		}
		Arrays.sort(dist);
		if (dist[0] == 0 || dist[5] == 0)
			return false;
		for (int i = 0; i < 2; i++) {
			if (dist[i] != dist[i + 1])
				return false;
		}

		return dist[4] == dist[5];
	}

	private long dist(long x1, long y1, long x2, long y2) {
		return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
	}

	static void rotate(int[][] m, int row) {
		int x = m[row][0] - m[row][2];
		int y = m[row][1] - m[row][3];
		m[row][0] = m[row][2] - y;
		m[row][1] = m[row][3] + x;
	}

	// didn't test
	static class BIT {
		int[] MAX;
		int[] MIN;
		int[] SUM;
		int n;

		public BIT(int n) {
			MAX = new int[n + 1];
			MIN = new int[n + 1];
			SUM = new int[n + 1];
			this.n = n;
		}

		public void setSum(int pos, int val) {
			for (int i = pos; i < n; i += (i & -i)) {
				SUM[i] += val;
			}
		}

		public int getSum(int to) {
			int sum = 0;
			for (int i = to; i > 0; i -= (i & -i)) {
				sum += SUM[i];
			}
			return sum;
		}

		public int getSum(int from, int to) {
			return getSum(to) - getSum(from);
		}

		public void setMax(int pos, int val) {
			for (int i = pos; i < n; i += (i & -i)) {
				MAX[i] = Math.max(val, MAX[i]);
			}
		}

		public int getMax(int to) {
			int max = 0;
			for (int i = to; i > 0; i -= (i & -i)) {
				max = Math.max(max, MAX[i]);
			}
			return max;
		}

		public void setMin(int pos, int val) {
			for (int i = pos; i < n; i += (i & -i)) {
				MIN[i] = Math.min(val, MIN[i]);
			}
		}

		public int getMin(int to) {
			int min = 0;
			for (int i = to; i > 0; i -= (i & -i)) {
				min = Math.min(min, MIN[i]);
			}
			return min;
		}

	}

	// didn't test
	static class DisjointSet {
		int[] set;

		public DisjointSet(int n) {
			set = new int[n];
			for (int i = 0; i < n; i++) {
				set[i] = i;
			}
		}

		public int findSet(int a) {
			if (set[a] == a)
				return a;
			return findSet(set[a]);
		}

		public void unionSet(int a, int b) {
			set[findSet(a)] = findSet(b);
		}

		public boolean isSameSet(int a, int b) {
			return findSet(a) == findSet(b);
		}
	}

	static class SegmentTree {
		int[] MAX;
		int[] MIN;
		int[] SUM;
		int[] data;
		int n;

		public SegmentTree(int[] data) {
			this.n = data.length;
			this.data = data;
			MAX = new int[4 * n + 10];
			MIN = new int[4 * n + 10];
			SUM = new int[4 * n + 10];
			buildTree(1, 0, n - 1);
		}

		public int left(int root) {
			return root << 1;
		}

		public int right(int root) {
			return (root << 1) + 1;
		}

		private void buildTree(int root, int rl, int rr) {
			if (rr == rl) {
				MAX[root] = MIN[root] = SUM[root] = data[rr];
			} else {
				int rm = (rl + rr) >> 1;
				buildTree(left(root), rl, rm);
				buildTree(right(root), rm + 1, rr);
				MAX[root] = Math.max(MAX[left(root)], MAX[right(root)]);
				MIN[root] = Math.min(MIN[left(root)], MIN[right(root)]);
				SUM[root] = SUM[left(root)] + SUM[right(root)];
			}
		}

		public int getMax(int from, int to) {
			return getMax(1, 0, n - 1, from, to);
		}

		private int getMax(int root, int rl, int rr, int from, int to) {
			if (from > rr || to < rl || rl > rr) {
				return -1;
			}
			if (from == rl && to == rr) {
				return MAX[root];
			}
			int rm = (rr + rl) >> 1;
			int m1 = getMax(left(root), rl, rm, from, Math.min(to, rm));
			int m2 = getMax(right(root), rm + 1, rr, Math.max(from, rm + 1), to);
			return Math.max(m1, m2);
		}

		public int getMin(int from, int to) {
			return getMin(1, 0, n - 1, from, to);
		}

		private int getMin(int root, int rl, int rr, int from, int to) {
			if (from > rr || to < rl || rl > rr) {
				return Integer.MAX_VALUE;
			}
			if (from == rl && to == rr) {
				return MIN[root];
			}
			int rm = (rr + rl) >> 1;
			int m1 = getMin(left(root), rl, rm, from, Math.min(to, rm));
			int m2 = getMin(right(root), rm + 1, rr, Math.max(from, rm + 1), to);
			return Math.min(m1, m2);
		}

		public int getSum(int from, int to) {
			return getSum(1, 0, n - 1, from, to);
		}

		private int getSum(int root, int rl, int rr, int from, int to) {
			if (from > rr || to < rl || rl > rr) {
				return 0;
			}
			if (from == rl && to == rr) {
				return SUM[root];
			}
			int rm = (rr + rl) >> 1;
			int m1 = getSum(left(root), rl, rm, from, Math.min(to, rm));
			int m2 = getSum(right(root), rm + 1, rr, Math.max(from, rm + 1), to);
			return m1 + m2;
		}
	}

	private String lcs(String s1, String s2) {
		int n = s1.length();
		int m = s2.length();
		int[][] dp = new int[n + 1][m + 1];
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {
				if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				} else {
					dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		int i = n;
		int j = m;
		while (i > 0 && j > 0) {
			if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
				sb.append(s1.charAt(i - 1));
				i--;
				j--;
			} else {
				if (dp[i - 1][j] > dp[i][j - 1]) {
					i--;
				} else {
					j--;
				}
			}
		}
		return sb.reverse().toString();
	}

	private boolean isPrime(int n) {
		if (n <= 3)
			return n > 1;
		else if (n % 3 == 0 || n % 2 == 0)
			return false;
		for (long i = 5; i * i <= n; i += 6) {
			if (n % i == 0 || n % (i + 2) == 0)
				return false;
		}
		return true;
	}

	private int[] getPrimes(int n) {
		int len = n + 1;
		boolean[] isPrimes = new boolean[len];
		int[] temps = new int[len];
		int index = 0;
		Arrays.fill(isPrimes, true);
		isPrimes[0] = isPrimes[1] = false;
		for (int i = 2; i * i < len; i++) {
			if (isPrimes[i]) {
				for (int j = i * i; j < len; j += i) {
					isPrimes[j] = false;
				}
			}
		}
		for (int i = 0; i < len; i++) {
			if (isPrimes[i])
				temps[index++] = i;
		}
		int[] primes = Arrays.copyOf(temps, index);
		return primes;
	}

	static void swap(char[] arrays, int pos1, int pos2) {
		char tmp = arrays[pos1];
		arrays[pos1] = arrays[pos2];
		arrays[pos2] = tmp;
	}

	static void swap(int[] arrays, int pos1, int pos2) {
		int tmp = arrays[pos1];
		arrays[pos1] = arrays[pos2];
		arrays[pos2] = tmp;
	}

	static long modPow(long n, long ex) {
		long res = 1;
		while (ex > 0) {
			if ((ex & 1) == 1)
				res = res * n % MOD;
			n = n * n % MOD;
			ex >>= 1;
		}
		return res;
	}

	static long ModInverse(long n) {
		return modPow(n, MOD - 2);
	}

	static long nCr(int n, int r) {
		if (r > n)
			return -1;
		// return (f[n] * ModInverse((f[r] * f[n - r]) % MOD)) % MOD;
		return 0;
	}
}

class Input {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public Input(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
		tokenizer = null;
	}

	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}
