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.util.*;
import java.io.*;
/*
99
557 852 325 459 557 350 719 719 400 228 985 674 942 322 212 553 191 58 720 262 798 884 20 275 576 971 684 340 581 175 641 552 190 277 293 928 261 504 83 950 423 211 571 159 44 428 131 273 181 555 430 437 901 376 361 989 225 399 712 935 279 975 525 631 442 558 457 904 491 598 321 396 537 555 73 415 842 162 284 847 847 139 305 150 300 664 831 894 260 747 466 563 97 907 42 340 553 471 411

2 1 4
1 5 3

3 3 5
58548 554082 511465
167004 905751 77513
923627 377573 296593
586327 565914 980256
173666 902633 791590

2 1 8
702710 573349 590290
704851 264410 4231
29781 952313 423934
239166 321919 952267
286137 653680 54247
84631 950349 631705
285243 351035 575133
4358 4713 638307

*/
public class eight 
{	
	public static void main(String[] arg) throws IOException
	{
		new eight();
	}
	public eight()
	{
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		long A = in.nextLong();
		long B = in.nextLong();
		long n = in.nextLong();
		while(n-- > 0)
		{
			long L = in.nextLong();
			long t = in.nextLong();
			long m = in.nextLong();
			
			long low = L;
			long high = 1_000_000_000l;
			long R = low + (high-low)/2;
			
			for(int cc = 0; cc < 100; cc++)
			{
				R = low+(high-low)/2;
				if(A+(R-1)*B <= t && A*(R-L+1) + B*sum(L, R)-B*(R-L+1) <= m*t)
				{
					low = R+1;
				}
				else
				{
					high = R-1;
				}
			}
			//out.println(low + " " + R + " " + high);
			if(high >= L) out.println(high);
			else out.println("-1");
		}
		in.close(); out.close();
	}
	long sum(long left, long right)
	{
		if(right < left) return 0;
		if(left != 0)
		{
			return sum(0, right)-sum(0, left-1);
		}
		return right*(right+1l)/2l;
	}
	class FastInput 
	{
		BufferedReader reader;
		StringTokenizer tokenizer;
		
		public FastInput(InputStream input)
		{
			reader = new BufferedReader(new InputStreamReader(input));
			tokenizer = new StringTokenizer("");
		}
		String next() throws IOException
		{
			while( ! tokenizer.hasMoreTokens() )
			{
				tokenizer = new StringTokenizer(reader.readLine());
			}
			return tokenizer.nextToken();
		}
		char nextChar() throws IOException { return next().charAt(0); }
		int nextInt() throws IOException { return Integer.parseInt(next()); }
		double nextDouble() throws IOException { return Double.parseDouble(next()); }
		long nextLong() throws IOException { return Long.parseLong(next()); }
		void close() throws IOException { reader.close(); }
	}
	class JoltyScanner 
	{
	    public static final int BUFFER_SIZE = 1 << 16;
		public static final char NULL_CHAR = (char) -1;

	    byte[] buffer = new byte[BUFFER_SIZE];
		boolean EOF_FLAG = false;
		int bufferIdx = 0, size = 0;
		char c = NULL_CHAR;
		BufferedInputStream in;

		public JoltyScanner(InputStream in) 
		{
			this.in = new BufferedInputStream(in, BUFFER_SIZE);
		}

		public int nextInt() 
		{
			long x = nextLong();
			if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) 
			{
				throw new ArithmeticException("Scanned value overflows integer");
			}
			return (int) x;
		}

		public long nextLong() 
		{
			boolean negative = false;
			if (c == NULL_CHAR) 
			{
				c = nextChar();
			}
			for (; !EOF_FLAG && (c < '0' || c > '9'); c = nextChar()) 
			{
				if (c == '-') 
				{
					negative = true;
				}				
			}
			checkEOF();
			long res = 0;
			for (; c >= '0' && c <= '9'; c = nextChar()) 
			{
				res = (res << 3) + (res << 1) + c - '0';
			}
			return negative ? -res : res;
		}

	    public char nextChar() 
	    {
			if (EOF_FLAG) 
			{
				return NULL_CHAR;
			}
			while (bufferIdx == size) 
			{
				try 
				{
					size = in.read(buffer);
					if (size == -1) 
					{
						throw new Exception();
					}
				} 
				catch (Exception e) 
				{
					EOF_FLAG = true;
					return NULL_CHAR;
				}
				if (size == -1) 
				{
					size = BUFFER_SIZE;
				}
				bufferIdx = 0;
			}
			return (char) buffer[bufferIdx++];
		}

	    public void checkEOF() 
	    {
			if (EOF_FLAG) 
			{
				throw new EndOfFileException();
			}
		}
	    public void close()
	    {
	    	;
	    }
		public class EndOfFileException extends RuntimeException 
		{
		}
	}
	class FastScanner 
	{
		final BufferedReader reader;
		String line;
		int index;
		public FastScanner(InputStream in)
		{
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String readLine()
		{
			try
			{
				String line = reader.readLine();
				if(line == null) throw new IOException("End of stream");
				return line;
			}
			catch(IOException exception)
			{
				throw new RuntimeException(exception);
			}
		}
		public String nextLine()
		{
			if(line==null) return readLine();
			String s = line;
			line = null;
			return s.substring(index);
		}
		public String next()
		{
			if(line == null)
			{
				line = readLine();
				index = 0;
			}
			while(index >= line.length())
			{
				line = readLine();
				index = 0;
			}
			while(Character.isWhitespace(line.charAt(index)))
			{
				index++;
				while(index >= line.length())
				{
					line = readLine();
					index = 0;
				}
			}
			int endIndex = index;
			while(endIndex < line.length() && !Character.isWhitespace(line.charAt(endIndex)))
				endIndex++;
			String s = line.substring(index, endIndex);
			index = endIndex;
			return s;
		}
		public int nextInt() { return Integer.parseInt(next()); }
		public long nextLong() { return Long.parseLong(next()); }
		public double nextDouble() { return Double.parseDouble(next()); }
		public void close() {;}
	}
}
