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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;


public class Main {
	static BufferedReader in;
	static PrintWriter out;

	public static long getAi(long A, long B, long index) {
		return A + (index-1)*B;
	}
	
	public static long getSum(long A, long B, long end) {
		return end*(getAi(A,B,1)+getAi(A,B,end))/2;
	}
	
	public static long getSum(long A, long B, long start, long end) {
		if (start==1) return getSum(A,B,end);
		else return getSum(A,B,end) - getSum(A,B,start-1);
	}
	
	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		String[] tok = rst();
		long A = Long.parseLong(tok[0]);
		long B = Long.parseLong(tok[1]);
		long n = Long.parseLong(tok[2]);

		for (int q=0;q<n;q++) {
			tok = rst();
			long l = Long.parseLong(tok[0]);
			long t = Long.parseLong(tok[1]);
			long m = Long.parseLong(tok[2]);
			long ans = 0;

			if (getAi(A,B,l)>t) {
				out.println(-1);
			} else {
				long lo = l, hi = (t-A)/B + 2, mid;
				while (getAi(A,B,hi)>t) hi--;
				long sum;
				while (hi-lo>1) {
					mid = (hi+lo) >>> 1;
					sum = getSum(A,B,l,mid);
					if (sum>t*m) {
						hi = mid-1;
					} else if (sum==t*m) {
						lo = hi = mid;
						break;
					} else {
						lo = mid;
					}
				}			
				sum = getSum(A,B,l,hi);
				if (sum<=t*m) ans = hi;
				else {
					sum = getSum(A,B,l,lo);
					if (sum<=t*m) ans = lo;
					else ans = -1;
				} 
				out.println(ans);
			}
		}

		in.close();
		out.close();
	}

	public static int ri() throws IOException {
		return Integer.parseInt(in.readLine());
	}

	public static long rl() throws IOException {
		return Long.parseLong(in.readLine());
	}

	public static String rs() throws IOException {
		return in.readLine();
	}

	public static String[] rst() throws IOException {
		return in.readLine().split(" ");
	}

	public static int[] rit() throws IOException {
		String[] tok = in.readLine().split(" ");
		int[] res = new int[tok.length];
		for (int i = 0; i < tok.length; i++) {
			res[i] = Integer.parseInt(tok[i]);
		}
		return res;
	}

	public static long[] rlt() throws IOException {
		String[] tok = in.readLine().split(" ");
		long[] res = new long[tok.length];
		for (int i = 0; i < tok.length; i++) {
			res[i] = Long.parseLong(tok[i]);
		}
		return res;
	}


}
