## Problem Description

A big integer with most of its digits being zeros is called a sparse big integer. Given a sparse big integer M and an integer N, you are to calculate M mod N.

## Input

The first line contains an integer representing the number of test cases. Each test case consists of two lines. In the first line of a test case, an integer K will be given first; then K pairs of integers follow, each indicates a non-zero digit with two integers D and P, which means the P-th digit of M from right to left is D. In the second line, the integer N will be given.

1 <= K <= 10; 1 <= D <= 9; 1 <= P <= 1000000000; 1 <= N <= 10000.

## Output

For each test case, print the result of M mod N in a single line.

## Sample Input

## Sample Output

## Source

FOJ月赛-2008年4月