Go: package main

import (
        "fmt"
)

func main() {
        var weeks = []string{"Thursday",
                "Friday",
                "Saturday",
                "Sunday",
                "Monday",
                "Tuesday",
                "Wednesday"}

        for {
                var m, d int
                _, err := fmt.Scanf("%d %d", &m, &d)
                if err != nil || m + d == 0 {
                        break
                }
                var days int

                for {
                        lm, ld := getLastDay(m, d)
                        if lm + ld == 0 {
                                break
                        }
                        days++
                        m = lm
                        d = ld
                }
                fmt.Println(weeks[days%7])
        }
}

func getLastDay(m int, d int) (lm int, ld int) {
        if m == 1 && d == 1 {
                return 0, 0
        }

        if d > 1 {
                return m, d-1
        } else {
                if m == 3 {
                        return m-1, 29
                }
                if m == 3 || m == 5 || m == 7 || m == 10 || m == 12 {
                        return m-1, 30
                } else {
                        return m-1, 31
                }
        }
}

C++: #include <iostream>
using namespace std;

int main(){
	int n,m;
	string a="Monday",s="Tuesday",d="Wednesday",f="Thursday",g="Friday",h="Saturday",j="Sunday";
	while(cin>>n>>m,n||m){
		if(n==4||n==6||n==9||n==11){
			if(n==4){
				if(m==1||m==8||m==15||m==22||m==29)cout<<f<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<g<<endl;
				else if(m==3||m==10||m==17||m==24)cout<<h<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<"Sunday"<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<"Monday"<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<"Tuesday"<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<"Wednesday"<<endl;
			}
			else if(n==6){
				if(m==1||m==8||m==15||m==22||m==29)cout<<s<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<d<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<f<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<g<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<h<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<j<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<a<<endl;
			}
			else if(n==9){
				if(m==1||m==8||m==15||m==22||m==29)cout<<d<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<f<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<g<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<h<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<j<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<a<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<s<<endl;
			}
			else{
				if(m==1||m==8||m==15||m==22||m==29)cout<<a<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<s<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<d<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<f<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<g<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<h<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<j<<endl;
			}
		}
		else if(n==1||n==3||n==5||n==7||n==8||n==10||n==12){
			if(n==1){
				if(m==1||m==8||m==15||m==22||m==29)cout<<"Thursday"<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<"Friday"<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<"Saturday"<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<"Sunday"<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<"Monday"<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<"Tuesday"<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<"Wednesday"<<endl;
			}
			else if(n==3){
				if(m==1||m==8||m==15||m==22||m==29)cout<<a<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<s<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<d<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<f<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<g<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<h<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<j<<endl;
			}
			else if(n==5){
				if(m==1||m==8||m==15||m==22||m==29)cout<<h<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<j<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<a<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<s<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<d<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<f<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<g<<endl;
			}
			else if(n==7){
				if(m==1||m==8||m==15||m==22||m==29)cout<<f<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<g<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<h<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<j<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<"Monday"<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<"Tuesday"<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<"Wednesday"<<endl;
			}
			else if(n==8){
				if(m==1||m==8||m==15||m==22||m==29)cout<<j<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<a<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<s<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<d<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<f<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<g<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<h<<endl;
			}
			else if(n==10){
				if(m==1||m==8||m==15||m==22||m==29)cout<<g<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<h<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<j<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<a<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<s<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<d<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<f<<endl;
			}
			else{
				if(m==1||m==8||m==15||m==22||m==29)cout<<d<<endl;
				else if(m==2||m==9||m==16||m==23||m==30)cout<<f<<endl;
				else if(m==3||m==10||m==17||m==24||m==31)cout<<g<<endl;
				else if(m==4||m==11||m==18||m==25)cout<<h<<endl;
				else if(m==5||m==12||m==19||m==26)cout<<j<<endl;
				else if(m==6||m==13||m==20||m==27)cout<<a<<endl;
				else if(m==7||m==14||m==21||m==28)cout<<s<<endl;
			}
		}
		else{
			if(m==1||m==8||m==15||m==22||m==29)cout<<j<<endl;
			else if(m==2||m==9||m==16||m==23)cout<<a<<endl;
			else if(m==3||m==10||m==17||m==24)cout<<s<<endl;
			else if(m==4||m==11||m==18||m==25)cout<<d<<endl;
			else if(m==5||m==12||m==19||m==26)cout<<f<<endl;
			else if(m==6||m==13||m==20||m==27)cout<<g<<endl;
			else if(m==7||m==14||m==21||m==28)cout<<h<<endl;
		}
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
string d[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int x[12]={31,29,31,30,31,30,31,31,30,31,30,31};
int y[12][31];
int main(){
	int a,b;
	while(true){
		cin>>a>>b;
		if(a==0){break;}
		int cnt=0;
		for(int i=0;i<12;i++){
			for(int j=0;j<x[i];j++){
				y[i][j]=cnt;
				cnt++;
			}
		}
		int D=y[a-1][b-1];
		D=(D+4)%7;
		cout<<d[D]<<endl;
	}
}

C++: 
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	
	string str[7] = {
		"Monday",
		"Tuesday",
		"Wednesday",
		"Thursday",
		"Friday",
		"Saturday",
		"Sunday"
	};
	int hoge[]={31,29,31,30,31,30,31,31,30,31,30,31};
	int m, d;
	while(1){
		cin>> m>> d;
		if(m==0&&d==0) break;
		int num = d;
		for(int i=0;i<m-1;i++){
			num += hoge[i];
		}
		int day = (2+num)%7;
		cout<< str[day]<< endl;
		
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}