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.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] argv) {
        MainRun mainSolve = new MainRun();
        mainSolve.run(0, 0);
    }
}

class Task {
	private final int MAXN = 10_000_000;
	public void solve(InputReader in, PrintWriter out) {
		int A = in.nextInt();
		int B = in.nextInt();
		int n = in.nextInt();
		
		long value[] = new long[MAXN];
		value[1] = A;
		long sum[] = new long[MAXN];
		sum[1] = A;
		for (int i = 2; i < MAXN; i++) {
			value[i] = value[i - 1] + B;
			sum[i] = sum[i - 1] + value[i];
		}
		for (int i = 0; i < n; i++) {
			int l = in.nextInt();
			int t = in.nextInt();
			int m = in.nextInt();
			if (value[l] > t) {
				out.println("-1");
				continue;
			}
			if (value[l] == t) {
				out.println(l);
				continue;
			}
			int L = l;
			int R = MAXN - 1;
			long mainSum = (long)t * m;
			while (R - L > 1) {
				int M = (L + R) / 2;
				long curSum = sum[M] - sum[l - 1];
				if (curSum <= mainSum && value[M] <= t)
					L = M;
				else
					R = M;
			}
			long curSum = sum[R] - sum[l - 1];
			if (curSum <= mainSum && value[R] <= t)
				out.println(R);
			else
				out.println(L);
		}
	}
}

class MainRun {
	void run(int inF, int outF) {
//		inF = outF = 0;
		String input = "input.txt";
//		String input = "large.in";	
		String output = "output.txt";
//		String output = "puzzle-2048.out";
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in;
		PrintWriter out;
		if (inF == 1)	
			in = new InputReader(input);
		else
			in = new InputReader(inputStream);
		if (outF == 1)
			out = getPrintWriter(output);
		else
			out = getPrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(in, out);
		out.close();
	}
	public static PrintWriter getPrintWriter(OutputStream stream) {
		return new PrintWriter(stream);
	}
	public static PrintWriter getPrintWriter(String f) {
		try {
			return new PrintWriter(new File(f));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		return null;
	}	
}

class InputReader {
	BufferedReader reader;
	StringTokenizer tokenizer;
	InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
		tokenizer = null;
	}
	InputReader(String f) {
		try {
			reader = new BufferedReader(new FileReader(f));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		tokenizer = null;		
	}
	public String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch(IOException e) {
				throw new RuntimeException(e);
			} catch(NullPointerException e) {
				return "";
			}
		}
		return tokenizer.nextToken();
	}
	public String getLine() {
		try {
			return (String)reader.readLine();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public char nextChar() {
		return next().charAt(0);
	}	
	public long nextLong() {
		return Long.parseLong(next());
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	public int[] nextIntArray(int n) {
		int a[] = new int[n + 2];
		for (int i = 1; i <= n; i++)
			a[i] = nextInt();
		return a;
	}
}