The Genome of Newton
On a planet Olimpiya a study the genome of inhabitants of the Olympic galaxy is completed. It appeared that the genome which deciphered can be given as a set of integers which can repeat. In presentation of the genome of talented personality among other there is a one which meets one times and determines the number of the certain genetically conditioned talent.
The developed equipment gets presentation to the genome as a set of plurals of numbers. Every plural is set of four numbers s, f, a, b. There are a послідовних successive integers belong to such plural beginning from s, next b numbers is not belonged to the plural, followings and belong again, and etc. All of numbers in a plural are no more then f. For example, a plural (s = 1, f = 10, a = 2, b = 1) has numbers: 1, 2, 4, 5, 7, 8, 10, and plural (s = 5, f = 50, a = 1, b = 19) has numbers: 5, 25, 45.
Write the program, that after presentation to the genome as a set of plurals of numbers will set, whether his proprietor has some genetically conditioned talent, and will define his number.
Input
There is the quantity of plurals N (1 ≤ N ≤ 10 000) in a set in the first line of input. Next N lines set plurals. Every plural is set of four numbers - s, f, a, b (1 ≤ s, f, a, b < 10^9; s ≤ f). It is guaranteed, that no more presentation to the genome contains one number which meets just one time.
Output
Print the number which meets odd number of times in genome presentation, or 0, if such number does not exist.