D :: 99 Red Balloons

Time Limit: 2 Seconds    Memory Limit: 65536 KB

Pejman is organizing the Internet ICPC contest of the University of Tehran. He needs a lot of balloons and asks Mohammad (the accountant of the scientific student chapter) for money. Mohammad has some problems with calculating the remaining money because of massive money transactions. The transactions are divided into three types as follows:

  • Electronic transactions: The money that is added to/withdrawn from account via the internet bank gateway
  • Strongbox transactions: The money that is added to/removed from strongbox placed in the chapter’s office
  • Future transactions: The money that will be paid/received at specific times in future

Mohammad has some bank accounts and all of bank transactions are Electronic transactions. Transactions between two different banks cost p percentage commission which is paid from the source account, but there is no commission for internal transactions, the transactions between the accounts in the same bank. Banks are distinguished by the first two digits of the account numbers. Also, banks pay interest to their customers. The interest is calculated hourly but it is not added to the account instantly. The interests are accumulated and added to the account on the first day of the next month (when the time is 00:00). When an hour passes, b percent of the current money is added to the interest. For example, if the account number 618546 contains 100$ at 14:25 of July 24th, 2014 and the value of b is 0.5, the interest amount at 16:00 of the same day is 50 cents and at 17:00 is 1$. The calculations’ accuracy of the banks is at most 0.00000001 dollar.
Strongbox transactions don’t have any commission or interest. The incomming money (anything paid to Mohammad) is directly added to the strongbox. For all the spendings, first it is paid from the strongbox and if there is not enough money, Mohammad will use his accounts in the increasing order of account numbers to pay the remaining amount.
Mohammad has written all of transactions and he wants to calculate the amount of his money when Pejman wants to buy the balloons. There is a possibility that he cannot pay future payments without considering Pejman’s balloons. Help Mohammad calculate the remaining money according to the given transactions.

Input

The input contains several test cases.
In the first line of input comes T (0 < T ≤ 30), the number of test cases.
For each test case, in the first line there are 3 dates and times. The first date-time is when accounts have been opened, the middle one is the current date and time and the last one is when Pejman wants to buy the balloons. Dates and times are displayed as yy/mm/dd-hh:mm. Note that the number of days in each month is 31,28,31,30,31,30,31,31,30,31,30 and 31, starting from January. We consider only the years after 2000 and before 2100 (00 to 99). And we don’t have any leap years!
In the second line, there are three integers: s, n and m, where 0 ≤ s ≤ 1000, 0 < n ≤ 10 and 0 < m ≤ 200 are the initial amount of money, accounts count and transactions count, respectively.
In the third line, there are two non-negative real numbers: p (a real number less than 20) which represents the commission percentage, and b (a real number less than 0.1) which represents the interest percentage of banks.
In the next n lines, there are two integers in each line: bn (bank account number) and a (initial amount of that account), where bn is a 6-digit number and 0 ≤ a ≤ 1000.
In the next m lines, there is a transaction in each line as follows.

  • Electronic transaction’s format is “%SBA %DBA %date-time %amount”. %SBA is the source bank account number, %DBA is the destination bank account number, %date-time is the date and time when the transaction occurred (before the current time) and %amount(dollar) is a positive integer.
  • Strongbox transaction’s format is “Safe %date-time %amount”. %date-time is the date and time when the transaction occurred (before the current time) and %amount is an integer. If positive, it represents the amount of dollars that has been added to strongbox, or the amount of dollars that has been paid from it, otherwise.
  • Future transaction’s format is “%BA %date-time %amount”. If %amount is positive, it will be added to strongbox; otherwise, added to %BA (the destination bank account number) at %date-time (it’s in the future). Exchanging money from strongbox to a bank account doesn’t have any commission.

In the last line, there are two numbers. The first one is a positive integer less than 500 that shows balloons’ price and the second one is Pejman’s bank account number.

Output

For each test case,

  • if there is no problem with future transactions and there is enough money to buy the balloons, output Happy Mohammad”.
  • else if there is no problem with future transactions but Mohammad can’t afford balloon’s money, output “Sad Mohammad”.
  • otherwise (if there is some problem with future transactions and Mohammad will be in debt), output Sad Sad Mohammad”.

Pay attention to the order of outputs.

Sample Input

2
13/05/14-09:16 14/10/27-18:25 14/11/12-12:00
500 2 6
1.5 0.002346
516482 100
493341 950
516482 502229 13/08/01-13:15 50
Safe 13/12/29-10:58 -300
516482 514832 13/11/07-15:01 50
493341 516482 14/09/20-11:31 800
631102 14/10/28-12:00 250
518240 14/11/03-10:30 500
150 512580
00/01/01-00:00 98/05/15-12:00 99/12/31-23:59
100 3 3
1.8 0.000023408
516482 500
493142 500
123456 500
516482 493142 05/05/05-05:05 496
493142 516482 06/05/05-05:05 980
526421 99/06/12-12:00 -1500
380 125268

Sample Output

Happy Mohammad
Sad Mohammad
Submit

Source: 12th Iran Nationwide Internet Contest - Final