In Panda Land the pandas have their own numeral system for writing numbers, and, surprisingly, it looks a lot like the Roman numerals of our own ancient history. Pandas cannot write (imagine a panda holding a pen!), so instead they cut and arrange bamboo stalks to spell out a number.
The rules for a Panda Number are:
These rules guarantee that every decimal number has exactly one Panda Number representation.
Unlike Roman numerals, pandas recognize zero and negative numbers (proof that pandas are more advanced than the ancient Romans). A negative number is written by placing one extra bamboo as a minus sign in front of the letters. Zero is special and obeys none of the rules above; forming a zero requires five bamboos.
The number of bamboos needed to form a number is the sum of the bamboos required by every letter that appears in it. For example:
Given two numbers A and B, determine how many bamboos the pandas need in total to form every number from A to B, inclusive.
| Decimal | Panda Number | Required Bamboo |
|---|---|---|
| 1 | I | 1 |
| 5 | V | 2 |
| 10 | X | 2 |
| 50 | L | 2 |
| 100 | C | 3 |
| 500 | N | 3 |
| 1,000 | M | 4 |
| 5,000 | E | 4 |
| 10,000 | W | 4 |
| 50,000 | F | 3 |
| 100,000 | Y | 3 |
| 500,000 | K | 3 |
| 1,000,000 | H | 3 |
| 5,000,000 | T | 2 |
| 10,000,000 | A | 3 |
The first line contains a single positive integer T, the number of test cases. Each of the next T lines contains two integers A and B (−25,000,000≤A≤B≤25,000,000).
For each test case, print on its own line the total number of bamboos needed to form every number from A to B, inclusive.