The first line contains two integers, representing the number of conferences Colin is interested in, and the number of papers Colin would like to submit.
For the followinglines, each line contains four integers
, representing the information for the
-th conference: it starts receiving submissions from 8 a.m. on day
, the deadline is 8 p.m. on day
, and authors will be notified results at 2 p.m. on day
whether their submissions are accepted. It's guaranteed the all the
are pairwise distinct.
For the followinglines, each line contains a single integer
, representing that Colin will finish the
-th paper at 9 a.m. on the day
.
For each paper, print a line with a single integer, representing the expected value of reputation points Colin could earn from it, modulo
.
For the first paper, Colin will submit it to the first conference, and according to the assumption, the paper will definitely be accepted. Thus, the expected value of reputation he could earn is equal to the impact factor of the first conference, which is.
For the second paper, Colin will first submit it to the second conference withprobability of being accepted. If it is rejected, he will receive the notification on the day
, then he will submit it to the fourth conference, with
probability of being accepted. If it is still rejected, he will receive the notification on day
, then he will submit it to the fifth conference, with
probability of being accepted. If it is still rejected, then there is no more chance to submit it. Thus, the expected value is
, which equals
modulo
.