Adding Reversed Numbers

Interview

Time limit1sMemory limit128 MB

Summary
Reverse two given numbers, add them, then output the sum reversed with leading zeros dropped.
Level

Easy3 of 10

Topics
String, Implementation, Math
Solved
No attempts yet

Problem

The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. The troupe's dramatic advisor has therefore decided to transfigure some tragedies into comedies. This work is hard, because the basic sense of the play must be kept intact even though everything turns into its opposite. Take numbers, for example: whenever a number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy.

A reversed number is a number written in Arabic numerals but with the order of its digits reversed. The first digit becomes the last and vice versa. For example, if the hero had 1245 strawberries in the tragedy, he now has 5421 of them. All leading zeros are omitted, so if a number ends with a zero, that zero is lost when it is reversed (e.g. 1200 gives 21). A reversed number therefore never has trailing zeros.

You must now calculate with reversed numbers. Add two reversed numbers and output their reversed sum. Because a given number is the reversed form of several numbers (e.g. 21 could be 12, 120, or 1200 before reversing), assume that no zeros were lost when the input numbers were originally reversed (e.g. assume the original of 21 was 12).

Input

The first line contains a single positive integer N, the number of cases. Each of the following N lines contains two positive integers separated by a space — the two reversed numbers you must add. Each integer is less than 100,000,000.

Output

For each case, print exactly one line containing a single integer: the reversed sum of the two reversed numbers. Omit any leading zeros.

Examples7

  1. Example 1

    Input
    3
    24 1
    4358 754
    305 794
    
    Expected output
    34
    1998
    1
    
  2. Example 2

    Input
    1
    1 1
    
    Expected output
    2
    
  3. Example 3

    Input
    1
    12 9
    
    Expected output
    3
    
  4. Example 4

    Input
    1
    1200 21
    
    Expected output
    33
    
  5. Example 5

    Input
    1
    99 1
    
    Expected output
    1
    
  6. Example 6

    Input
    4
    100 100
    50 50
    1 999
    1000 1
    
    Expected output
    2
    1
    1
    2
    
  7. Example 7

    Input
    1
    10203 30201
    
    Expected output
    40404