Problem:
What day is today? Your task is to write a program which reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thursday. Note that 2004 is a leap year and we have Feb. 29. Input The input is a sequence of datasets. The end of the input is indicated by a line containing one zero. Each dataset consists of two integers m and d separated by a single space in a line. These integers respectively represent the month and the day. The number of datasets is less than or equal to 50. Output For each dataset, print the day (please see the following words) in a line. Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday Sample Input 1 1
2 29
0 0 Output for the Sample Input Thursday
Sunday

Solution (Python):
while True:
    a,b=map(int,input().split())
    c=0
    if a==0:
        break
    tuki=[31,29,31,30,31,30,31,31,30,31,30,31]
    a-=1
    for i in range(a):
        c=c+tuki[i]
    c+=b
    if c%7==1:
        ans="Thursday"
    if c%7==2:
        ans="Friday"
    if c%7==3:
        ans="Saturday"
    if c%7==4:
        ans="Sunday"
    if c%7==5:
        ans="Monday"
    if c%7==6:
        ans="Tuesday"
    if c%7==0:
        ans="Wednesday"
    print(ans)

Solution (Python):
month=[31,29,31,30,31,30,31,31,30,31,30,31]
week =['Wednesday','Thursday','Friday','Saturday','Sunday','Monday','Tuesday']

while True:
    sum=0
    m,d=map(int,raw_input().split())
    if m==0 and d==0:
        break
    else:
        for i in range(m-1):
            sum += month[i]
        sum += d
        flag = sum % 7
        print week[flag]

Solution (Python):
import datetime
for e in iter(input,'0 0'):print(['Mon','Tues','Wednes','Thurs','Fri','Satur','Sun'][datetime.date(2004,*map(int,e.split())).weekday()]+'day')

Solution (Python):
import datetime
for e in iter(input,'0 0'):print(['Mon','Tues','Wednes','Thurs','Fri','Satur','Sun'][datetime.date(2004,*map(int,e.split())).weekday()]+'day')

Solution (Python):
import datetime
for e in iter(input,'0 0'):print(['Mon','Tues','Wednes','Thurs','Fri','Satur','Sun'][datetime.date(2004,*map(int,e.split())).weekday()]+'day')

Solution (Python):
for e in iter(input,'0 0'):
 m,d=map(int,e.split())
 print(['Wednes','Thurs','Fri','Satur','Sun','Mon','Tues'][([0,31,60,91,121,152,182,213,244,274,305,335][m-1]+d)%7]+'day')

Solution (Python):
import datetime
for e in iter(input,'0 0'):print(datetime.date(2004,*map(int,e.split())).strftime("%A"))

Solution (Python):
from datetime import *
for e in iter(input,'0 0'):print(date(2004,*map(int,e.split())).strftime("%A"))

Solution (Python):
from datetime import *
for e in iter(input,'0 0'):print(date(2004,*map(int,e.split())).strftime("%A"))

Solution (Python):
from datetime import *
for e in iter(input,'0 0'):print(date(2004,*map(int,e.split())).strftime('%A'))

Solution (Python):
from datetime import *
for e in iter(input,'0 0'):print(date(2004,*map(int,e.split())).strftime('%A'))

Solution (Python):
from datetime import *
for e in iter(input,'0 0'):print(date(2004,*map(int,e.split())).strftime('%A'))

Solution (Python):
from datetime import *
for e in iter(input,'0 0'):print(date(2004,*map(int,e.split())).strftime('%A'))

Solution (Python):
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

daylist = [31,29,31,30,31,30,31,31,30,31,30,31]
namelist = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

N = list(get_input())
m,d = [int(i) for i in N[0].split()]
cnt = 1
while m != 0 or d != 0:
    ans = 2
    for i in range(m-1):
        ans += daylist[i]
    ans += d
    ans %= 7
    print(namelist[ans])

    m,d = [int(i) for i in N[cnt].split()]
    cnt += 1

Solution (Python):

day_1_list = [4, 7, 1, 4, 6, 2, 4, 7, 3, 5, 1, 3]

while True:
    month, day = map(int, input().split())
    if month == 0:
        break
    dw = (day_1_list[month-1] + day - 1) % 7
    if dw == 1:
        print("Monday")
    elif dw == 2:
        print("Tuesday")
    elif dw == 3:
        print("Wednesday")
    elif dw == 4:
        print("Thursday")
    elif dw == 5:
        print("Friday")
    elif dw == 6:
        print("Saturday")
    elif dw == 0:
        print("Sunday")

Solution (Python):
while 1:
	day = ['Wednes','Thurs','Fri','Satur','Sun','Mon','Tues']
	month = [0,31,60,91,121,152,182,213,244,274,305,335]
	m,d=map(int,input().split())
	if m == 0:
		break
	print(day[(month[m-1]+d)%7]+'day')

Solution (Python):
from datetime import datetime

youbi = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

while True:
    line = input()
    if line.strip() == '0 0':
        break
    else:
        month, day = map(int, line.strip().split(' '))
        f = '%Y-%m-%d'
        a = datetime.strptime('2004-{}-{}'.format(month, day), f)
        print(youbi[a.weekday()])

Solution (Python):
s = (0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30)
w = ("Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday")
while True:
    m, d = map(int, input().split())
    if m == 0:break
    print(w[(d + sum(s[:m])) % 7])

Solution (Python):
from datetime import datetime

y = 2004

while (True):
    m, d = map(int, input().split())
    if m == 0: break

    day = datetime(y, m, d)
    print(day.strftime('%A'))

Solution (Python):
from datetime import datetime
r=[]
while 1:
    l=list(map(int,input().split()))
    if not l[0] and not l[1]:break
    r.extend([datetime(year=2004,month=l[0],day=l[1]).weekday()])
for i in r:
    if i==0:print("Monday")
    elif i==1:print("Tuesday")
    elif i==2:print("Wednesday")
    elif i==3:print("Thursday")
    elif i==4:print("Friday")
    elif i==5:print("Saturday")
    elif i==6:print("Sunday")

Solution (Python):
from datetime import date

dic = {0:"Monday", 1:"Tuesday", 2:"Wednesday", 3:"Thursday", 4:"Friday", 5:"Saturday", 6:"Sunday"}

while True:
  month, day = map(int, input().split())
  
  if not month:
    break

  print(dic[date(2004, month, day).weekday()])

Solution (Python):



def Zeller(y, m, d):
    if m == 1 or  m == 2:
        y -= 1
        m += 12
    return (y + y//4 - y//100 + y//400 + (13*m + 8)//5 + d) % 7

import sys
week = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
for line in sys.stdin:
    m, d = list(map(int, line.split()))
    if m >= 1:
        print(week[Zeller(2004, m, d)])
    else:
        break

Solution (Python):
def day(Y, m, d, Gregorian=True):
    from math import floor

    
    if m <= 2:
        Y -= 1
        m += 12
    y = Y%100
    c = Y//100
    g = 5*c+floor(c/4) if Gregorian else 5-c
    return (d + floor(26*(m+1)/10) + y + floor(y/4) +  g) %7 

day_en = ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]

while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    print(day_en[day(2004, m, d)])

Solution (Python):
import sys

dictionary = {
        0:0,
        1:31,
        2:60,
        3:91,
        4:121,
        5:152,
        6:182,
        7:213,
        8:244,
        9:274,
        10:305,
        11:335,
        12:366}

for line in sys.stdin.readlines():
    line = line.strip()
    month, day = map(int, line.split())
    if month == 0:
        break
    else:
        pastDay = dictionary[month - 1] + day - 1
        if pastDay % 7 == 0:
            print "Thursday"
        elif pastDay % 7 == 1:
            print "Friday"
        elif pastDay % 7 == 2:
            print "Saturday"
        elif pastDay % 7 == 3:
            print "Sunday"
        elif pastDay % 7 == 4:
            print "Monday"
        elif pastDay % 7 == 5:
            print "Tuesday"
        else:
            print "Wednesday"

Solution (Python):

dates = []
youbi = []

for i in range(1,13):
    if i == 1 or i == 3 or i == 5 or i == 7 or i == 8 or i == 10 or i == 12:
        for j in range(1,32):
            dates.append([i,j])
    elif i == 4 or i == 6 or i == 9 or i == 11:
        for j in range(1,31):
            dates.append([i,j])
    elif i == 2:
        for j in range(1,30):
            dates.append([i,j])

while True:
    x = map(int, raw_input().split(' '))
    if x == [0,0]:
        for yo in youbi:
            print yo
        break
    elif dates.index(x) % 7 == 0:
        youbi.append('Thursday')
    elif dates.index(x) % 7 == 1:
        youbi.append('Friday')
    elif dates.index(x) % 7 == 2:
        youbi.append('Saturday')
    elif dates.index(x) % 7 == 3:
        youbi.append('Sunday')
    elif dates.index(x) % 7 == 4:
        youbi.append('Monday')
    elif dates.index(x) % 7 == 5:
        youbi.append('Tuesday')
    elif dates.index(x) % 7 == 6:
        youbi.append('Wednesday')

Solution (Python):
import calendar
week={0:"Monday",
      1:"Tuesday",
      2:"Wednesday",
      3:"Thursday",
      4:"Friday",
      5:"Saturday",
      6:"Sunday"}
while True:
    month,day=map(int,raw_input().split())
    if month==0:break
    print week[calendar.weekday(2004,month,day)]

Solution (Python):
import calendar
while True:
    month,day=map(int,raw_input().split())
    if month==0:break
    print calendar.day_name[calendar.weekday(2004,month,day)]

Solution (Python):
day = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"]
month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
while True:
	m, d = map(int, raw_input().split())
	if m == d == 0: break
	print day[(sum(month[0:m-1]) + d - 1) % 7]

Solution (Python):



import sys
import datetime

"""
Input
    複数のデータセットを処理しなければなりません。
    １つのデータセットに月と日が１つのスペース区切られて１行に与えられます。
    月が 0 となったとき入力の最後とします
    （この場合は処理をしないでプログラムを終了させる）。

Output
    各データセットごとに曜日を英語で１行に出力して下さい。
    以下の訳を参考にして出力して下さい。

    Monday
    Tuesday
    Wednesday
    Thursday
    Friday
    Saturday
    Sunday
"""


def get_weekday(month, day):
    weekdays = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
    return weekdays[datetime.date(2004, month, day).weekday()]


def main():
    while 1:
        s = sys.stdin.readline()
        month, day = [int(x) for x in s.split(" ")]
        if month == 0:
            return
        print get_weekday(month, day)

if __name__ == '__main__':
    main()

Solution (Python):
import datetime
week = ["Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday", "Saturday", "Sunday"]
while True:
    (m, d) = [int(i) for i in raw_input().split()]
    if m == 0:
        break
    dt = datetime.datetime(2004, m, d)
    print week[dt.weekday()]

Solution (Python):
ans=[]
week=[
      'Monday',         
      'Tuesday',        
      'Wednesday',      
      'Thursday',       
      'Friday',         
      'Saturday',       
      'Sunday'          
      ]
year=[
      2, 5, 6, 2, 4, 0, 2, 5, 1, 3, 6, 1
      ]
while True:
    month,day=map(int,raw_input().split())
    if month==0 and day==0:
        break
    ans.append(week[ (year[month-1] + day) %7])
    
for i in ans:
    print i

Solution (Python):
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin
from datetime import date

for line in stdin:
    if line.startswith('0 0'):
        break
    print(date(2004, *(int(s) for s in line.split())).strftime('%A'))

Solution (Python):
import datetime
while True:
	x = map(int,raw_input().split(' '))
	if x[0] != 0:
		day = datetime.date(2004,x[0],x[1])
		weekday = day.isoweekday()
		if weekday == 1:
			print 'Monday'
		if weekday == 2:
			print 'Tuesday'
		if weekday == 3:
			print 'Wednesday'
		if weekday == 4:
			print 'Thursday'
		if weekday == 5:
			print 'Friday'
		if weekday == 6:
			print 'Saturday'
		if weekday == 7:
			print 'Sunday'
		continue
	else:
		break

Solution (Python):
import datetime
week=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
while 1:
    month,day=map(int,raw_input().split())
    if month==0:break;
    print week[datetime.datetime(2004,month,day).weekday()]

Solution (Python):
a=['Wednesday','Thursday','Friday','Saturday','Sunday','Monday','Tuesday',0]
while True:
    q=map(int,raw_input().split())
    if sum(q) == 0: break
    print a[(sum([0,31,29,31,30,31,30,31,31,30,31,30,31][:q[0]])+q[1])%7]

Solution (Python):
while True:
    q=map(int,raw_input().split())
    if sum(q) == 0: break
    print ['Wednesday','Thursday','Friday','Saturday','Sunday','Monday','Tuesday',0][(sum([0,31,29,31,30,31,30,31,31,30,31,30,31][:q[0]])+q[1])%7]

Solution (Python):

import sys
from datetime import datetime


y = 2004



for line in sys.stdin:
    (m, d) = tuple(map(int, line.split(' ')))
    if m == 0:
        break
    date = datetime(y, m, d)
    print date.strftime("%A")

Solution (Python):
nm = [0,31,29,31,30,31,30,31,31,30,31,30]
while True:

    m,d = map(int,raw_input().split(" "))

    if m == 0:
        break
    else:
        nd = 0
        for i in range(m):
           nd += nm[i]

        nd += d
        n = nd%7
        if n == 1:
            print "Thursday"
        elif n == 2:
            print "Friday"
        elif n == 3:
            print "Saturday"
        elif n == 4:
            print "Sunday"
        elif n == 5:
            print "Monday"
        elif n == 6:
            print "Tuesday"
        else:                                                                                                                                                                                                
            print "Wednesday"

Solution (Python):
weekday=["Monday", "Tuesday", "Wednesday", "Thursday",
         "Friday", "Saturday", "Sunday"]

def monthday(month):
    if month in [1,3,5,7,8,10,12]: return 31
    elif month in [4,6,9,11]: return 30
    else: return 29

def days(month, day):
    return sum([monthday(i) for  i in range(1, month)]) + day
   
while True:
    m, d = map(int, raw_input().split())
    if m==0: break
    diff = days(m,d)-1
    print weekday[(diff +3)% 7]

Solution (Python):
import datetime

w = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

while True:
    m,d = map(int, raw_input().split())
    if m == 0:
        break
    print w[datetime.date(2004, m, d).weekday()]

Solution (Python):
import datetime
import sys

weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

for line in sys.stdin:
    data = line.strip().split()
    m = data[0]
    d = data[1]
    if m == '0':
        break

    date = datetime.datetime.strptime('2004-' + m + '-' + d + ' 13:13:13', '%Y-%m-%d %H:%M:%S')
    print weekdays[date.weekday()]

Solution (Python):
y = [31,29,31,30,31,30,31,31,30,31,30,31]
dow = {0:"Monday", 1:"Tuesday", 2:"Wednesday", 3:"Thursday", 4:"Friday", 5:"Saturday", 6:"Sunday"}

while True:
    m, d = map(int, raw_input().split())
    if m == 0 and d == 0:
        break
    n = 0
    for i in range(m):
        n += y[i]
    n -= (y[m-1]-d+1)
    print dow[(n+3)%7]

Solution (Python):
wd=["Mon","Tues","Wednes","Thurs","Fri","Satur","Sun"]
md=[0,31,29,31,30,31,30,31,31,30,31,30,31]

while 1:
    m,d = map(int, raw_input().split())
    if m==0: break
    s = sum([md[i] for i in range(m)]) + d + 2
    s = wd[s % 7]+"day"
    print s

Solution (Python):
import datetime
WEEKDAY = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
while 1:
    a, b = map(int, raw_input().split())
    if a == b == 0:
        break
    print WEEKDAY[datetime.date(2004, a, b).weekday()]

Solution (Python):
import datetime
while True:
    m, d = map(int, raw_input().split())
    if m == 0 and d == 0:
        break
    print ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'][datetime.date(2004, m, d).weekday()]

Solution (Python):
days=(31,29,31,30,31,30,31,31,30,31,30,31)
day=('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')
while True:
	total=0
	m,d=map(int,raw_input().split(" "))
	if m!=0:
		for i in range(m-1):
			total+=days[i]
		total+=d
		print day[(total+3)%7]
	else:
		break

Solution (Python):
dw = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
dm = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)

while True:
    m, d = map(int, input().split())
    if m == d == 0: break

    total = sum(dm[i] for i in range(m - 1)) + d - 1
    print(dw[(total + 4) % 7])

Solution (Python):
day = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30]
for i in range(2,12):
    day[i] += day[i-1]
week = ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday']
while True:
    M, D = map(int, input().split())
    if M==0:
        break
    days = day[M-1] + D
    print(week[days%7])

Solution (Python):
lst = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
while True:
    m, d = map(int, input().split())
    if m == 0:
        break
    
    if m == 1 or m == 4 or m == 7:
        print(lst[(d + 2) % 7])

    elif m == 2 or m == 8:
        print(lst[(d + 5) % 7])

    elif m == 3 or m == 11:
        print(lst[(d + 6) % 7])

    elif m == 5:
        print(lst[(d + 4) % 7])

    elif m == 6:
        print(lst[d % 7])

    elif m == 9 or m == 12:
        print(lst[(d + 1) % 7])

    else:
        print(lst[(d + 3) % 7])

Solution (Python):
while 1:
    m,d = map(int,input().split())
    if m == 0:
        break
    w = ["Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"]
    day = [0,31,60,91,121,152,182,213,244,274,305,335]
    print(w[(day[m-1]+d)%7])

Solution (Python):

import datetime


while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0:break

    
    youbi = datetime.datetime(2004,a,b)
    print(youbi.strftime("%A"))

Solution (Python):
from datetime import date
import calendar


while True:
    m,d = map(int,(input().split()))
    if m == 0 and d == 0:
        break
    x = date(2004,m,d).weekday()
    print(["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"][x])

Solution (Python):
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def convert(y, m, d):
    if m <= 2:
        m += 12
        y -= 1
    mjd = int(365.25*y) + (y//400) - (y//100) + int(30.59*(m-2)) + d - 678912
    return mjd

youbi = [
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday",
]

def solve():
    m, d = map(int, readline().split())
    if m == 0:
        return False
    write("%s\n" % youbi[(convert(2004, m, d) - convert(2004, 1, 1) + 3) % 7])
    return True
while solve():
    ...

Solution (Python):
while True :
    M, D = map(int, input().split())
    if M == 0 and D == 0 :
        break

    else :
        if M == 1 :
            days = D
        elif M == 2 :
            days = 31 + D
        elif M == 3 :
            days = 31+29+D
        elif M == 4 :
            days = 31+29+31+D
        elif M == 5 :
            days = 31+29+31+30+D
        elif M == 6 :
            days = 31+29+31+30+31+D
        elif M == 7 :
            days = 31+29+31+30+31+30+D
        elif M == 8 :
            days = 31+29+31+30+31+30+31+D
        elif M == 9 :
            days = 31+29+31+30+31+30+31+31+D
        elif M == 10 :
            days = 31+29+31+30+31+30+31+31+30+D
        elif M == 11 :
            days = 31+29+31+30+31+30+31+31+30+31+D
        elif M == 12 :
            days = 31+29+31+30+31+30+31+31+30+31+30+D
            
        youbi = days % 7
        if youbi == 0 :
            print("Wednesday")
        elif youbi == 1 :
            print("Thursday")
        elif youbi == 2 :
            print("Friday")
        elif youbi == 3 :
            print("Saturday")
        elif youbi == 4 :
            print("Sunday")
        elif youbi == 5 :
            print("Monday")
        elif youbi == 6 :
            print("Tuesday")

Solution (Python):
from datetime import date

dic = {0:"Monday", 1:"Tuesday", 2:"Wednesday", 3:"Thursday", 4:"Friday", 5:"Saturday", 6:"Sunday"}

while True:
  month, day = map(int, input().split())
  
  if not month:
    break

  print(dic[date(2004, month, day).weekday()])

Solution (Python):
from datetime import date
days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]

while True:
  month,day = map(int, input().split())
  
  if month == 0:
    break

  print(days[date(2004, month, day).weekday()])

Solution (Python):
import datetime
yobi = {0:"Monday",1:"Tuesday",2:"Wednesday",3:"Thursday",4:"Friday",5:"Saturday",6:"Sunday"}
try:
    while True:
        m, d= map(int, input().split())
        if m == 0 and d == 0 :
            exit()
        day = datetime.datetime.strptime("2004/" + str(m) + "/" + str(d),"%Y/%m/%d")
        if day.weekday() in yobi:
            output = yobi[int(day.weekday())]
            print(output)
except EOFError:
    pass

Solution (Python):
month = [0,31,60,91,121,152,182,213,244,274,305,335]
day = ["Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"]
while True:
    a,b = map(int,input().split())
    if a == 0:
        break
    num = month[a-1]+b
    print(day[num%7])

Solution (Python):






import sys
import math


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans
    
    
    def is_integer(self, n):
        try:
            float(n)
        except ValueError:
            return False
        else:
            return float(n).is_integer()

    
    def dist(self, A, B):
        d = 0
        for i in range(len(A)):
            d += (A[i]-B[i])**2            
        d = d**(1/2)
        return d

    
    def abs(self, n):
        if n >= 0:
            return n
        else:
            return -n

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()






















def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()










def get_input():
    N = []
    while True:
        try:
            N.append(input())
            
            
            
        except EOFError:
            break
    return N


M = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
A = ["Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday"]
 
while True:
    m, d = [int(x) for x in input().split()]
    if m==0 and d==0:
        break
    B = (sum(M[:m])+d-1)%7
    print(A[B])

Solution (Python):
import datetime

while 1:
    m, d = map(int, input().split())
    if m == 0:
        break
    dt = datetime.datetime(2004, m, d)

    print(dt.strftime('%A'))

Solution (Python):

import datetime
L = [ "Monday", "Tuesday", "Wednesday", "Thursday","Friday",
      "Saturday", "Sunday" ]

while True:
    m, d = [int(x) for x in input().split()]
    if m == 0 and d == 0:
        break
    dt = datetime.datetime(2004, m, d)
    w = dt.weekday()
    print(L[w])

Solution (Python):
while True:
    month,day=list(map(int, input().split()))
    if month==day==0:
        break
    month_day=[30,29,31,30,31,30,31,31,30,31,30,31]             
    tmp_day=0
    for i in range(month-1):
        tmp_day+=month_day[i]
    tmp_day+=day
    amari=tmp_day%7
    if month==day==1:
        print("Thursday")
    elif amari==0:
        print("Thursday")
    elif amari==1:
        print("Friday")
    elif amari==2:
        print("Saturday")
    elif amari==3:
        print("Sunday")
    elif amari==4:
        print("Monday")
    elif amari==5:
        print("Tuesday")
    elif amari==6:
        print("Wednesday")

Solution (Python):
import sys

def zeller(y,m,d):
  if m==1 or m==2:
    y-=1
    m+=12
  day=(y+int(y/4)-int(y/100)+int(y/400)+int((13*m+8)/5)+d)%7
  D={0:'Sunday',1:'Monday',2:'Tuesday',3:'Wednesday',4:'Thursday',5:'Friday',6:'Saturday'}
  return D[day]
  

for l in sys.stdin:
  m,d=list(map(int,l.split()))
  if m==0:
    break
  print(zeller(2004,m,d))

Solution (Python):
w = ["Wednesday", "Thursday", "Friday",
     "Saturday", "Sunday", "Monday", "Tuesday"]
a = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
while 1:
    m, d = map(int, input().split())
    if m == 0:
        break
    s = 0
    for i in range(m - 1):
        s += a[i]

    print(w[(s+d) % 7])

Solution (Python):
import datetime
 
week=["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
while True:
    a,b=map(int, input().split())
    if a == b == 0:
        break
    print(week[datetime.date(2004, a, b).weekday()])

Solution (Python):
W = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
M = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
 
while True:
    m, d = map(int, input().split())
    if m == d == 0: break
 
    total = sum(M[i] for i in range(m - 1)) + d - 1
    print(W[(total + 4) % 7])

Solution (Python):
import sys
 
day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
num = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
 
for s in sys.stdin:
    M, D = map(int, s.strip().split())
    if M == 0:
        break
    totalDay = D
    M -= 1
 
    while M > 0:
        totalDay += num[M-1]
        M -= 1
 
    print(day[(totalDay+2)%7])

Solution (Python):
import datetime

num2wd={0:"Monday",1:"Tuesday",2:"Wednesday",3:"Thursday",4:"Friday",5:"Saturday",6:"Sunday"}

while True:
    m,d=[int(i) for i in input().split(" ")]
    if m==0 and d==0:
        break

    date=datetime.datetime(2004,m,d)
    print(num2wd[date.weekday()])

Solution (Python):
if __name__ == '__main__':

	W = ["Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"]
	Y = [31,29,31,30,31,30,31,31,30,31,30,31]

	while True:
		m,d = map(int,input().split())
		if m == 0 and d == 0:
			break

		day = 0
		for i in range(m-1):
			day += Y[i]
		day += d

		ans = day % 7
		print(W[ans-1])

Solution (Python):
m = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
d = ["Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"]
while True:
  a, b = map(int, input().split())
  if a + b == 0:
    break
  mon = 0
  for i in range(a):
    mon += m[i]
  day = mon + b
  print(d[day % 7])

Solution (Python):
month = [3, 1, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3]

while True:
  m, d = map(int, input().split())
  if m == 0:
    break
  piv = 3
  for i in range(m-1):
    piv += month[i]
  piv += d
  piv %= 7
  if piv == 0:
    print("Sunday")
  elif piv == 1:
    print("Monday")
  elif piv == 2:
    print("Tuesday")
  elif piv == 3:
    print("Wednesday")
  elif piv == 4:
    print("Thursday")
  elif piv == 5:
    print("Friday")
  elif piv == 6:
    print("Saturday")

Solution (Python):
days = ['Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'Monday', 'Tuesday']
month = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30]
while True:
	m, d = map(int, raw_input().split())
	if m == 0: break
	for i in range(0, m):
		d += month[i]
	print days[d%7]

Solution (Python):
import datetime
while 1:
    m,d=map(int,input().split())
    if m==d==0:break
    ans=datetime.datetime(2004, m, d)
    print(ans.strftime('%A'))

Solution (Python):
ndays = [31,29,31,30,31,30,31,31,30,31,30,31]
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
offset = 3
while(1):
	m,d = [int(i) for i in input().split()]
	if m == 0 and d == 0:
		break
	tot_d = sum(ndays[:m-1]) + d 
	print(days[(tot_d + offset - 1)%7])

Solution (Python):
from datetime import *
wd_map = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
while True:
    month, day = map(int, input().split())
    if month == 0:
        break
    print(wd_map[date(2004, month, day).weekday()])

Solution (Python):
daylist = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
week = ["Wednesday", "Thursday", "Friday", "Saturday",
        "Sunday", "Monday", "Tuesday"]

while(1):
    m, d = map(int, input().split())
    if m == 0:
        break

    day = 0
    for i in range(m-1):
        day += daylist[i]
    day += d

    w = week[day % 7]
    print(w)

Solution (Python):
lastDayofLastMonth = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]
dateList = ["Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"]
inputData = []

while True:
    inputData = list(map(int, input().split()))
    if inputData[0]==0:
        break
    dd_date = lastDayofLastMonth[inputData[0]-1] + inputData[1]
    print(dateList[dd_date%7])

Solution (Python):
import datetime
import calendar

def trans(month, day, year=2004):
    past = datetime.date(year, month, day)
    result = calendar.day_name[past.weekday()]
    return result
    
while True:
    month, day = map(int, input().split())
    if month == day == 0: break
    print(trans(month, day))

Solution (Python):
import datetime
import sys
i_weekday = { i:weekday for i, weekday in enumerate('Monday Tuesday Wednesday Thursday Friday Saturday Sunday'.split() ) }
while True:
  M, D = map(int, input().split())
  if M == 0:
    sys.exit()
  dt = datetime.datetime.strptime(f'2004-{M}-{D}', '%Y-%m-%d')
  
  print(i_weekday[ dt.weekday() ] )

Solution (Python):
while(True):
    m,d = map(int,input().split())
    if m==0 and d==0:
        break
    dn = sum([[31,29,31,30,31,30,31,31,30,31,30,31][a] for a in range(m-1)]) + d-1
    print(["Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"][dn%7])

Solution (Python):
import datetime
while 1:
    try:
        m,d=map(int, input().split())
        print(datetime.date(2004, m,d).strftime('%A'))
    except:break

Solution (Python):
def solve():
    day = [
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday',
        'Sunday',
        'Monday',
        'Tuesday',
    ]
    
    days_month = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    days_total = []
    for i in range(len(days_month)):
        days_total.append(sum(days_month[0:i]))
    
    while True:
        mm, dd = map(int, input().split())
        if mm == 0 and dd == 0:
            break
        
        numd = days_total[mm - 1]
        total = numd + dd
        idx = total % len(day)
        
        print(day[idx])
    

if __name__ == "__main__":
    solve()