问题 H: Umamusume

内存限制:512 MB 时间限制:10 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

"Makea newtrack" is a new mode of game "Umamusume".During the game,there will be n rounds to improve attributes,each round can choose between rest,train or race.

����rest:add 50 TP

�����train:spend 50 TP and add 15 speed points(TP less than 50 will fail)

����race:spend 50 TP and add 100 G(TP less than 50 will fail)

At first round,you have 100 TP.

You can spend G in a special store to obtain items,special store will refresh the items that can be buy every 6 rounds(Round 6 will be the earliest time to buy items).The probability of each item appearing in the store is p(It can exist in a store and not sell anything and the number of one type of item is only one).Different item have different price and features:

item name price function
TP Medicine(L) 100G add 100 TP
TP Medicine(M) 50G add 50 TP
TP Medicine(S) 25G add 25 TP
Magic Book(L) 100G add 15 speed points
Magic Book(M) 50G add 7 speed points
Magic Book(S) 25G add 3 speed points
Horn 100G next training speed points will become 2x
Weight 200G next training speed points will spend 100 TP but become 3x
(Weight can not be used together with Horn)

Each item can be bought more than one time and you can use the item on any round after you buy it.

In order to obtain the strongest and fastest umamusume in the game,you know all the items in the store at first,and you are smart.You want to know the expected speed points.

Please output it modulo 109+7109+7.

输入格式

The input consists of multiple test cases. The first line contains a single integer �(1≤�≤10000)T(1T10000) — the number of test cases.

The each test case contains contains two integers nand p (0≤�≤109,0≤�<109+7)(0n109,0p<109+7)—This means that the number of rounds and the probability of each item appearing in the store.

输出格式

For each test case, output an integer representing the expected speed points modulo 109+7109+7.

输入样例 复制

3
2 1
5 500000004
27 500000004

输出样例 复制

30
45
857330545

分类标签