🏡 index : github.com/captn3m0/codechef.git

---
category_name: easy
problem_code: H4
problem_name: 'Just a simple sum'
languages_supported:
    - C
    - CPP14
    - JAVA
    - PYTH
    - 'PYTH 3.5'
    - PYPY
    - CS2
    - 'PAS fpc'
    - 'PAS gpc'
    - RUBY
    - PHP
    - GO
    - NODEJS
    - HASK
    - rust
    - SCALA
    - swift
    - D
    - PERL
    - FORT
    - WSPC
    - ADA
    - CAML
    - ICK
    - BF
    - ASM
    - CLPS
    - PRLG
    - ICON
    - 'SCM qobi'
    - PIKE
    - ST
    - NICE
    - LUA
    - BASH
    - NEM
    - 'LISP sbcl'
    - 'LISP clisp'
    - 'SCM guile'
    - TCL
    - kotlin
    - TEXT
    - 'SCM chicken'
    - CLOJ
    - COB
    - FS
max_timelimit: '2.13807 - 17.1046'
source_sizelimit: '50000'
problem_author: admin
problem_tester: null
date_added: 15-09-2009
tags:
    - admin
time:
    view_start_date: 1255253400
    submit_start_date: 1255253400
    visible_start_date: 1255253400
    end_date: 1735669800
    current: 1525198935
is_direct_submittable: false
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><strong>Input:</strong>
6
1 100000
2 100000
3 100000
4 100000
5 100000
6 100000

<strong>Output:</strong>
1
5
32
288
3413
50069
</pre>