King's Heir#9443

King's Heir

1 Sekunde
128 Megabyte
Sehr leicht

The king is dead, long live the king! After the sudden death of the king Fert XIII the people of the Flatland Kingdom are going to welcome the new king. Unfortunately, there is a problem, Fert has too many sons.

Actually, he has sons and he loved each new son more than all of his previous sons. Well, probably he just stopped loving his sons because of their bad behavior. Anyway, after the new son was born Fert made the new testament that declared that the newly born son would be the heir.

However, there is a problem. Only the king's son who is at least years old at the moment of the king's death can become a new king. Now the ministers of the government are trying to find the correct new king, but they seem to fail. Help them!

Eingabe

The first line contains three integers: , and - the day, the month and the year of the king's death, is from to , is from to , is from to . It is guaranteed that there exists day in month , all months have the same number of days in Flatland as in our country, except that Flatland calendar doesn't have leap years, so February (month ) always has days.

The second line contains (1 \leq n \leq 100) - the number of king's sons. The following lines contain three integers each d_i, m_i and y_i and specify the birth dates of king's sons. All dates are correct and no son is born after or on the day of king's death. The king had no twins, so no two sons were born on the same date.

Ausgabe

Output one integer - the number of the son that would become the king, or if none of them is at least years old. The sons are numbered from to in order they are described in the input. The youngest son who is at least years old at the moment of the king's death would become the king. If the son has his 18th birthday exactly on the day of the king's death, he can become a king.

Beispiele

Beispiel 1

Loading
Loading

Beispiel 2

Loading
Loading