CALCULAT - 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 (1<= N <=108), K (1<= K <=50), L (1<= L <=100), 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
Note : for all test cases whose N>=100, its K<=15.

Added by:Fudan University Problem Setters
Date:2007-12-01
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO
Resource:IPSC 2006

hide comments
2024-03-02 05:51:07 David
There are a few pathological cases that make this problem a little difficult!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.