IPSC Logo

Internet Problem Solving Contest

IPSC 2006

Problem D – Digital Calculator

Dan likes playing with his pocket calculator during those long, boring math classes. Just now the teacher started to talk about the factorial function.

N factorial, denoted by N!, is the product of all the integers between 1 and N, inclusive. For example 6! = 6*5*4*3*2*1 = 720.

Dan took out his calculator out of his pocket to play around with this new function. Unfortunately his calculator quickly ran out of digits and only showed overflow errors. Soon, Dan realized that the factorial function grows very quickly. Still, he would like to know at least some of its digits.

Problem specification

Given three positive integers N, K, L, compute the first K digits and the last L digits of N factorial.

Input specification

The first line of the input file contains an integer T specifying the number of test cases. Each test case is preceded by a blank line.

Each test case consists of one line containing three positive integers N, K and L separated by single spaces. Neither K nor L will exceed the number of digits in N!.

Output specification:

For each test case output one line containing two strings A and B separated by a single space. Here, A is the string composed of the first K digits of N! and B is the string composed of the last L digits of N!.

Example

Input:
3

6 2 1

10 3 2

8 5 5
Output:
72 0
362 00
40320 40320

Credits:
Problemsetter(s): misof
Contest-related materials: palo