#P8547. 小挖的时间

小挖的时间

Problem Description

Xiao Wa has a digital clock that uses a 1212-hour format and shows only hours and minutes, i.e., it only displays 12:0011:5912:00 \sim 11:59. The time after 12:5912:59 is 1:001:00.

The hour has no leading zero, but the minutes may have one (for example, 7:597:59 will not be written as 07:5907:59, while 10:0310:03 will not be written as 10:310:3).

Starting from noon of some day (i.e., 12:0012:00), Xiao Wa stares at this digital clock for a total of TT minutes. They now want to know: how many times in total will they see a time whose digits form an arithmetic progression?

The definition of an arithmetic progression is as follows: if a sequence is an arithmetic progression, then every number after the first equals the previous one plus a fixed common difference. For example, 11:1111:11 is such a time with common difference 00, and 12:3412:34 is such a time with common difference 11.

If you look carefully, you will notice that the common difference is not restricted in sign, so it can be positive or negative.

Input Format

Line 11: a positive integer DD, meaning this test point contains DD groups of testdata.

Lines 2D+12 \sim D + 1: each line contains a non-negative integer TT, with the meaning described above.

Output Format

Output DD lines in total. Each line contains an integer ansans, representing the number of arithmetic-progression times seen.

6
34
60
100
118
50
106
1
1
4
5
1
4

Hint

For 30%30\% of the data, 0T600 \leq T \leq 60.

For 60%60\% of the data, 0T1050 \leq T \leq 10^5.

For 100%100\% of the data, 0T1090 \leq T \leq 10^9, 1D5001 \leq D \leq 500.

Sample Explanation

For the first query 3434, the interval is from 12:0012:3412:00 \sim 12:34. Only 12:3412:34 satisfies the requirement.

For the third query 100100, the interval is from 12:001:4012:00 \sim 1:40. There are four times that satisfy the requirement: 12:34,1:11,1:23,1:3512:34, 1:11, 1:23, 1:35.

For the fourth query 118118, the interval is from 12:001:5812:00 \sim 1:58. There are five times that satisfy the requirement: 12:34,1:11,1:23,1:35,1:4712:34, 1:11, 1:23, 1:35, 1:47.

Translated by ChatGPT 5