Problem: You are playing another computer game, and now you have to slay monsters. These monsters are standing in a circle, numbered clockwise from to . Initially, the -th monster has health.
You may shoot the monsters to kill them. Each shot requires exactly one bullet and decreases the health of the targeted monster by (deals damage to it). Furthermore, when the health of some monster becomes or less than , it dies and explodes, dealing damage to the next monster (monster , if , or monster , if ). If the next monster is already dead, then nothing happens. If the explosion kills the next monster, it explodes too, damaging the monster after it and possibly triggering another explosion, and so on.
You have to calculate the minimum number of bullets you have to fire to kill all monsters in the circle.
Input Format: The first line contains one integer () — the number of test cases.
Then the test cases follow, each test case begins with a line containing one integer () — the number of monsters. Then lines follow, each containing two integers and () — the parameters of the -th monster in the circle.
It is guaranteed that the total number of monsters in all test cases does not exceed .
Output Format: For each test case, print one integer — the minimum number of bullets you have to fire to kill all of the monsters.