#Lutece0105. Apple Pie

Apple Pie

Migrated from Lutece 105 Apple Pie

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Apple pie is Hysramp's favorite snack for tasting so cloying, which usually formed in circular appearance. Although exotic and delicious, apple pie is not so abstruse of its cooking method. Just as the figure shows, looks pretty charming ,apple pie is often make of a big round bread and several pieces of apple slices.

However, what often discomfit Hysramp is, everyone may meet, mouth appears not big enough to touch any apple slices when eat the apple pie for the first bite. Now given the apple pie and the bite mark, you’re required to tell how many apple slices have Hysramp touched.

To simplify the problem, we do some reasonable assumptions. Apple pie (yellow part) and apple slices (red parts) on it all are exact circles. Each circle will be described by an RR for radius and XX, YY for centre. The bite mark on the apple pie must be a minor arc (the blue arc), which will be given by two points and a radius rr. These two points will be guaranteed on the edge of apple pie, thus they (the two points) will be indicated by two degree PP, QQ, which is the degrees from the positive XX-axis on coordinate system which the origin is on the apple pie's centre, just as illustrated below.

.

Input

The first line of the input contains one integer TT, which indicate the number of test cases. Following each test case will be separated by a blank line.

For each test, the first line would be four integers, RR, XX, YY, NN, separate by spaces, which are radius and centre coordinate of the apple pie (yellow), then followed by NN lines. Each line has three integers rr, xx, yy, separate by spaces, describing the apple slices (red). The last line of each test case is rr, PP and QQ, in degree (0P,Q<3600\leq P, Q < 360), which mentioned in the problem. And all data will be less than 50005000.

Output

One line for each test case, output Bad Apple Pie if any apple slices fails to lie completely in the apple pie, or write the number of apple slices Hysramp can touch with the given bite mark.

Samples

1
100 200 170 2
30 140 180
50 220 180
100 160 70
2

Note

  1. Apple slices (the red parts) may not completely lie in the apple pie (the yellow part), if so, output Bad Apple Pie.
  2. The apple slices (the red parts) may overlap on each other, but it doesn't matter.
  3. The bite mark will always be a minor arc and Hysramp would never bite off the centre of the apple pie for some reasons.
  4. Ex-tangency of a circle and arc also means touch, and in-tangency of two circles also means include.

Resources

The 7th UESTC Programming Contest Final