This page is still under construction.

Parts of this page are still being built. What you see may change.

November 11

Interview

Time limit2sMemory limit1024 MB

Summary
For each year and month, find the date that is m days before month m, day m of that year, using the calendar with leap-year rules.
Level

Easy2 of 10

Topics
Implementation, Simulation
Solved
No attempts yet

Problem

On November 11, there are several observances: Farmers' Day, Garaetteok Day, Pedestrian Day, the founding anniversary of the Republic of Korea Navy, the Memorial Day for UN Veterans, and Pepero Day. Seonghyeon found that 11 days before November 11 is October 31, which is Halloween. He plans to get Pepero from a friend on the next Halloween.

Seonghyeon wondered whether another special day exists at the date mm days before month mm, day mm, like November 11. Write a program that finds the date mm days before month mm, day mm.

The months 1, 3, 5, 7, 8, 10, and 12 have 31 days. The months 4, 6, 9, and 11 have 30 days. February has 28 days in a common year and 29 days in a leap year. A leap year is a year that is a multiple of 4 but not a multiple of 100, or a multiple of 400.

Input

The first line contains the number of dates TT to compute. (1≤T≤1 2121 \leq T \leq 1\,212)

From the second line, TT lines follow, each giving one date. Each date is given as a year yiy_i and a month mim_i, separated by a space. (2000≤yi≤21002000 \leq y_i \leq 2100, 1≤mi≤121 \leq m_i \leq 12)

Output

Print TT lines.

On line ii, print the year, month, and day, separated by spaces, of the date that is mim_i days before month mim_i, day mim_i of year yiy_i.

Examples1

  1. Example 1

    Input
    6
    2000 3
    2012 3
    2022 3
    2100 3
    2022 1
    2022 11
    
    Expected output
    2000 2 29
    2012 2 29
    2022 2 28
    2100 2 28
    2021 12 31
    2022 10 31