Mr.X owns a small business in a region with poor law-and-order. Recently his warehouse has been plagued by thieves. Gangs of thieves raid over his warehouse from time to time, stealing his raw material, affecting his business. He has studied the occurrences and noticed it that they are cyclical.
Assuming that a work week starts every Monday, and Sat and Sun are holidays, predict the total number of days when business would be affected.
Ex:
He has noticed that currently there seem to be 2 gangs. Gang 1 raids every 4 days, whereas Gang 2 strikes every 6 days.( See attached image )
Raids On Holidays are okay - since there is no raw material on those days. If more than gang raids the warehouse on a particular day, it is still counted as one bad day only . So the answer in this case is 5.
Sample Input:
2
2
4 6
21
3
3 4 8
14
The first line indicates the number of test cases - 2 above. Each test case is made up of 3 lines.
The first line of every test case indicates the number of gangs, n. (i.e 2 for Test Cases#1)
The next line contains n integers, where each number k indicates that the gang strikes every k days. (i.e. 4 and 6 for TestCase#1)
The next line is the number of days d, for which the prediction is needed. 0 <= d <= 365 (i.e. 21 days for TestCase#1)
Sample output:
5
5