When ?? was born, seven crows flew in and stopped beside him. In its childhood, ?? had been unfortunately fall into the sea. While it was dying, seven dolphins arched its body and sent it back to the shore. It is said that ?? used to surrounded by 7 candles when he faced a extremely difficult problem, and always solve it in seven minutes.

?? once wrote an autobiography, which mentioned something about himself. In his book, it said seven is his favorite number and he thinks that a number can be divisible by seven can bring him good luck. On the other hand, ?? abhors some other prime numbers and thinks a number x divided by pi which is one of these prime numbers with a given remainder ai will bring him bad luck. In this case, many of his lucky numbers are sullied because they can be divisible by 7 and also has a remainder of ai when it is divided by the prime number pi.

Now give you a pair of x and y, and N pairs of ai and pi, please find out how many numbers between x and y can bring ?? good luck.

?? once wrote an autobiography, which mentioned something about himself. In his book, it said seven is his favorite number and he thinks that a number can be divisible by seven can bring him good luck. On the other hand, ?? abhors some other prime numbers and thinks a number x divided by pi which is one of these prime numbers with a given remainder ai will bring him bad luck. In this case, many of his lucky numbers are sullied because they can be divisible by 7 and also has a remainder of ai when it is divided by the prime number pi.

Now give you a pair of x and y, and N pairs of ai and pi, please find out how many numbers between x and y can bring ?? good luck.

On the first line there is an integer T(T≤20) representing the number of test cases.

Each test case starts with three integers three intergers n, x, y(0<=n<=15,0<x<y<$10^{18}$) on a line where n is the number of pirmes.

Following on n lines each contains two integers pi, ai where pi is the pirme and ?? abhors the numbers have a remainder of ai when they are divided by pi.

It is guranteed that all the pi are distinct and pi!=7.

It is also guaranteed that p1*p2*…*pn<=$10^{18}$ and 0<ai<pi<=$10^{5}$for every i∈(1…n).

Each test case starts with three integers three intergers n, x, y(0<=n<=15,0<x<y<$10^{18}$) on a line where n is the number of pirmes.

Following on n lines each contains two integers pi, ai where pi is the pirme and ?? abhors the numbers have a remainder of ai when they are divided by pi.

It is guranteed that all the pi are distinct and pi!=7.

It is also guaranteed that p1*p2*…*pn<=$10^{18}$ and 0<ai<pi<=$10^{5}$for every i∈(1…n).

For each test case, first output "Case #x: ",x=1,2,3...., then output the correct answer on a line.

提交代码