1198. Mathematician QSC

时间限制 1000 ms   内存限制 128 MB

 QSC dream of becoming a mathematician, he believes that everything in this world has a mathematical law.

 Through unremitting efforts, one day he finally found the QSC sequence, it is a very magical sequence, can be calculated by a series of calculations to predict the results of a course of a semester of a student.

 This sequence is such like that, first of all, . Then the definition of the QSC sequence is . If we know the birthday of the student is n, the year at the beginning of the semester is y, the course number x and the course total score s, then the forecast mark is .

 QSC sequence published caused a sensation, after a number of students to find out the results of the prediction is very accurate, the shortcoming is the complex calculation. As clever as you are, can you write a program to predict the mark?


输入数据

First line is an integer T(1≤T≤1000).

The next T lines were given n, y, x, s, respectively.

n、x is 8 bits decimal integer, for example, 00001234.

y is 4 bits decimal integer, for example, 1234.

nx、y are not negetive.

C:%5CUsers%5Czhblue%5CAppData%5CLocal%5CTemp%5Cksohtml%5Cwps8BBA.tmp.png

 

输出数据

For each test case the output is only one integer number ans in a line.

样例输入

复制
2
20160830 2016 12345678 666
20101010 2014 03030303 333
 \n
        ·    ·        ·   \n
        ·    ·        ·   \n

样例输出

复制
1
317
 \n
   \n

样例说明

数学家QSC

(时间:1s,空间:128Mb

 

 QSC梦想成为数学家,他相信世间的一切都有数学规律。

 经过不懈的努力,有一天他终于发现了QSC数列,那是一个很牛逼的数列,可以通过一系列计算预测某人某学期某门课的成绩。

 这个数列是这样的,首先有C:%5CUsers%5Czhblue%5CAppData%5CLocal%5CTemp%5Cksohtml%5Cwps3A0C.tmp.png,那么定义QSC数列C:%5CUsers%5Czhblue%5CAppData%5CLocal%5CTemp%5Cksohtml%5Cwps3A0D.tmp.png,若已知某人的生日n,学期开始时的年份y,课程编号x和课程总分s,则预测成绩为C:%5CUsers%5Czhblue%5CAppData%5CLocal%5CTemp%5Cksohtml%5Cwps3A1E.tmp.png

 QSC数列公布后引起了轰动,经多位同学亲身试验后发现预测结果十分精确,缺点是计算比较复杂,聪明的你能编写一个程序来预测成绩吗?


Input

第一行一个整数T,表示T(1≤T≤1000)组数据。

接下来T行每行分别给出n,y,x,s。

n、x为8位整数允许有前导零

y为4位整数允许有前导零

C:%5CUsers%5Czhblue%5CAppData%5CLocal%5CTemp%5Cksohtml%5Cwps3A1F.tmp.png

Output

对于每组数据,输出成绩,一组数据一行。


样例输入

2

20160830 2016 12345678 666

20101010 2014 03030303 333

样例输出

1

317

提交

请先 登录

© 2024 FAQs Contact About