P8534 "Wdoi-2" A Dream Redder Than Scarlet
Background
This is in the mountains of the Eastern Country, far away from human villages. Hakurei Shrine exists on such a border.
This mountain originally had no one living on it, and even now it is a place that most people would never set foot in. People call it Gensokyo.
-----
One mansion, two incidents, opened the prelude to Gensokyo’s spell card battles.
It was the summer of season 118. From the red Western-style mansion, countless red mist burst out, and the sky of Gensokyo was dyed crimson. The Hakurei shrine maiden Hakurei Reimu and the Western magician Kirisame Marisa noticed this strange mist and hurried out. What awaited them was the first incident under spell card rules. Along with a huge Yin-Yang Orb smashing down from the sky and destroying the entire Scarlet Devil Mansion, the Red Mist Incident came to an end. This was the performance of the former “two-colored lotus butterfly” and the black-and-white magician.
But this time, the two protagonists, having lost their memories, forgot all kinds of events along the way, whether it was the dignified vampire, or that string of magic circles in the Great Library. They only know that this is an incident that urgently needs them to solve. However, because the first incident was mysterious and special, they hope you can tell them how many lives (remaining lives) in total they can spend freely.
Description
In the game story of *Touhou Koumakyou*, there are six stages, called $\text{Stage 1}\sim \text{Stage 6}$.
When the score reaches (i.e., is greater than or equal to) $10{,}000{,}000$, $20{,}000{,}000$, $40{,}000{,}000$, and $60{,}000{,}000$, the protagonist will be rewarded with one extra life (i.e., one “life”) each time. In addition, during the midboss section of $\text{Stage 3}$ and $\text{Stage 5}$, the protagonist will be rewarded with one extra life. The protagonist starts with $2$ lives.
Even though Reimu and Marisa have lost their memories, their instinct to dodge bullet patterns will not be forgotten. That is, they will not consume any lives during the game. Now the protagonist has just cleared $\text{Stage }x$, and the protagonist’s score is $s$. How many lives does the protagonist have now?
Input Format
**This problem contains multiple test cases.**
- The first line contains an integer $T$, the number of test cases.
- For each test case, input one line with two integers $x$ and $s$.
Output Format
- For each test case, output one integer per line, representing the number of lives the protagonist currently has.
Explanation/Hint
### Sample Explanation
- For the $1$st test case, the protagonist only cleared the first stage and scored $0$ points, so there are only the initial $2$ lives.
- For the $2$nd test case, the protagonist cleared the first stage and got a very high score, enough to obtain all score-based extra lives. The answer is $2$ (initial lives) $+4$ (score rewards) $=6$ lives.
- For the $3$rd test case, the protagonist cleared the game, but the score is very low. The protagonist gets the initial $2$ lives, the mid-stage reward life in $\text{Stage 3}$, and the mid-stage reward life in $\text{Stage 5}$, for a total of $4$ lives.
### Constraints
$$
\def\arraystretch{1.5}
\begin{array}{|c|c|c|c|c|}\hline
\textbf{Subtask} & \bm{x\le} & \bm{s\le} & \bm{T\le} & \textbf{Score}\\\hline
1 & 1 & 0 & 1 & 5\\\hline
2 & 6 & 0 & 100 & 10 \\\hline
3 & 6 & 10^9 & 10^4 & 10 \\\hline
4 & 6 & 10^{18} & 10^4 & 75 \\\hline
\end{array}$$
For all testdata, $1 \le T \le 10^4$, $1 \le x \le 6$, $0 \le s \le 10^{18}$ holds.
Translated by ChatGPT 5