Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓
統計

Sia $x$ un intero rappresentato da $n$ cifre identiche $a$ in base $r$. Inoltre, sia $y$ un intero la cui rappresentazione consiste di $m$ cifre $b$ in base $r$.

Trova la somma delle cifre del numero $z = x \cdot y$ rappresentato in base $r$, e stampa anche questa somma delle cifre in base $r$.

Input

La prima riga contiene un singolo intero $t$ ($1 \le t \le 10\,000$): il numero di casi di test. Segue la descrizione dei casi di test.

Ogni caso di test consiste di una singola riga contenente cinque interi $n, m, a, b, r$ ($n, m \ge 1, n + m \le 10^{18}, 1 \le a, b < r \le 10$).

Output

Per ogni caso di test, stampa un singolo intero su una riga separata: la risposta al problema in base $r$.

Esempio

Input di esempio 1

5
2 3 6 6 10
6 11 7 7 10
20 25 2 6 10
13 37 1 1 2
57 1 4 2 8

Output di esempio 1

27
84
204
100101
71

Note

Nel primo caso di test, abbiamo $x = 66_{10}, y = 666_{10}, z = 43\,956_{10}$. La somma delle cifre di $z$ è $27_{10}$.

Nel quarto caso di test, la somma delle cifre di $z$ nella rappresentazione binaria è $37_{10} = 100101_2$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.