Digits - MarisaOJ: Marisa Online Judge

Digits

Time limit: 1000 ms
Memory limit: 256 MB
The sequence number is calculated using the formula: $f(n) = (a^b + c^d) \mod 10$ **Task**: Given four positive integers $a$, $b$, $c$, and $d$ $(1 \leq a, b, c, d \leq 10^9)$, find the last digit of $f(n)$. #### Input - The first line contains a positive integer $T$ $(1 \leq T \leq 10^5)$, which is the number of data sets. - The following $T$ lines each contain four positive integers $a$, $b$, $c$, and $d$. #### Output - Print $T$ lines, each containing a single digit, which is the last digit of $f(n)$ for the corresponding input data set. #### Example Input: ``` 2 1 1 1 3 1 1 3 3 ``` Output: ``` 4 2 ``` #### Subtasks - **Subtask 1 (40 points)**: $a, b, c, d \leq 10^3$. - **Subtask 2 (30 points)**: $a, b, c, d \leq 10^5$. - **Subtask 3 (30 points)**: No additional constraints.