---
languages_supported:
- NA
title: H4
category: NA
old_version: true
problem_code: H4
tags:
- NA
layout: problem
---
### All submissions for this problem are available.
Given n and m, calculate 11 + 22 + 33 + ... + nn modulo m.
### Input
The first line contains 1 ≤ t ≤ 10, the number of test cases. Then the test case definitions follow. Each test case is of the form: 1 ≤ n ≤ 1018, 1 ≤ m ≤ 200000
### Output
For each test case simply write a single line containing the answer to the problem.
### Example
<pre><b>Input:</b>
6
1 100000
2 100000
3 100000
4 100000
5 100000
6 100000
<b>Output:</b>
1
5
32
288
3413
50069
</pre>