#include <iostream>
using namespace std;
class Date
{
	friend ostream& operator<<(ostream& out, const Date& d);
	friend istream& operator>>(istream& in, Date& d);
public:
	Date(int year = 1, int month = 1, int day = 1 );
	bool operator==(const Date& d);
	bool operator>=(const Date& d);
	bool operator<=(const Date& d);
	bool operator>(const Date& d);
	bool operator<(const Date& d);
	bool operator!=(const Date& d);
	Date& operator+=(int day);
	Date& operator-=(int day);
	Date operator+(int day);
	Date operator-(int day);

	Date& operator++();//前置
	Date operator++(int);//后置
	Date& operator--();//前置
	Date operator--(int);//后置
	int operator-(const Date&d);
	inline int GetDay(int year,int month)//获取天数,内联函数
	{
		static int GetMonthDay[13] = { -1,31,28,31,30,31,30,31,31,30,31,30,31 };
		if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
		{
			return 29;
		}
		else
		{
			return GetMonthDay[month];
		}
	}
//private:
	int _year;
	int _month;
	int _day;
};
ostream& operator<<(ostream& out, const Date& d);
istream& operator>>(istream& in,  Date& d);

Date::Date(int year  , int month  , int day )
{
	_year = year;
	_month = month;
	_day = day;
}
bool Date::operator==(const Date& d)
{
	return _year == d._month
		&& _month == d._month
		&& _day == d._day;
}
bool Date::operator>(const Date& d)
{
	if (_year > d._year)
	{
		return true;
	}
	else if (_year == d._year)
	{
		if (_month > d._month)
		{
			return true;
		}
		else if(_month==d._month)
		{
			if (_day > d._day)
			{
				return true;
			}
		}
	}
	return false;
}
bool Date::operator<=(const Date& d)
{
	return (! (*this > d)) || (*this == d);
}
bool Date::operator>=(const Date& d)
{
	return (*this > d) || (*this == d);
}
bool Date::operator<(const Date& d)
{
	return !(*this >= d);
}
bool Date::operator!=(const Date& d)
{
	return !(*this == d);
}
Date& Date::operator+=(int day)
{
	if (day < 0)
	{
		return *this -= -day;
	}
	_day += day;
	while (_day > GetDay(_year,_month))
	{
		_day -= GetDay(_year,_month);
		++_month;
		if (_month == 13)
		{
			++_year;
			_month = 1;
		}
	}
	return *this;
}
Date& Date::operator-=(int day)
{
	if (day < 0)
	{
		return *this += -day;
	}
	_day -= day;
	while (_day <= 0)
		{
			--_month;
			if (_month == 0)
			{
				-- _year;
				_month = 12;
			}
			_day += GetDay(_year, _month);
		}
	if (_day > GetDay(_year, _month))
	{
		_day = GetDay(_year, _month) - _day;
	}
	return *this;
}
Date Date::operator+(int day)
{
	Date tmp = *this;
	tmp += day;
	return tmp;
}
Date Date::operator-(int day)
{
	Date tmp = *this;
	tmp -= day;//复用
	return tmp;
}
Date& Date::operator++()//前置
{
	*this += 1;
	return *this;
}
Date Date:: operator++(int)//后置
{
	Date tmp(*this);
	*this += 1;
	return tmp;
}
Date& Date:: operator--()//前置
{
	*this -= 1;
	return *this;
}
Date Date::operator--(int)//后置
{
	Date tmp(*this);
	*this -= 1;
	return tmp;
}
int Date::operator-(const Date& d)
{
	int flag = 1;
	Date max = *this;
	Date min = d;
	if (*this < d)
	{
		max = d;
		min = *this;
		flag = -1;
	}
	int day = 0;
	while (min < max)
	{
		++(min);
		++day;
	}
	return day * flag;

}
ostream& operator<<(ostream& out, const Date& d)
{
	if(d._month<10 && d._day<10)
    {
        out<<d._year<<"-"<<0<<d._month<<"-"<<0<<d._day<<endl;
    }
    else if(d._month<10 && d._day>=10)
    {
        out<<d._year<<"-"<<0<<d._month<<"-"<<d._day<<endl;
    }
    if(d._month>=10 && d._day<10 )
    {
         out<<d._year<<"-"<<d._month<<"-"<<0<<d._day<<endl;
    }
    else if(d._month>=10 && d._day>=10 )
    {
         out<<d._year<<"-"<<d._month<<"-"<<d._day<<endl;
    }
	return out;
}
istream& operator>>(istream& in, Date& d)
{
	in >> d._year  >> d._month >> d._day;
	return in;
}
int main()
{
    int m = 0;
    int i = 0;
    int day = 0;
    cin>>m;
    Date *pf = new Date[m];
    for(i=0;i<m;i++)
    {
        cin>>pf[i]>>day;
        pf[i]+=day;
		cout<<pf[i];
    }
	delete []pf;
    return 0;




















}