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>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int m,d;
    while(cin>>m>>d){
        if(m==0&&d==0){
            break;
        }
        if(m==1||m==4||m==7){
            if(d%7==1){
                cout<<"Thursday"<<endl;
            }else if(d%7==2){
                cout<<"Friday"<<endl;
            }else if(d%7==3){
                cout<<"Saturday"<<endl;
            }else if(d%7==4){
                cout<<"Sunday"<<endl;
            }else if(d%7==5){
                cout<<"Monday"<<endl;
            }else if(d%7==6){
                cout<<"Tuesday"<<endl;
            }else if(d%7==0){
                cout<<"Wednesday"<<endl;
            }
        }
        if(m==2||m==8){
            if(d%7==5){
                cout<<"Thursday"<<endl;
            }else if(d%7==6){
                cout<<"Friday"<<endl;
            }else if(d%7==0){
                cout<<"Saturday"<<endl;
            }else if(d%7==1){
                cout<<"Sunday"<<endl;
            }else if(d%7==2){
                cout<<"Monday"<<endl;
            }else if(d%7==3){
                cout<<"Tuesday"<<endl;
            }else if(d%7==4){
                cout<<"Wednesday"<<endl;
            }
        }
        if(m==3){
            if(d%7==4){
                cout<<"Thursday"<<endl;
            }else if(d%7==5){
                cout<<"Friday"<<endl;
            }else if(d%7==6){
                cout<<"Saturday"<<endl;
            }else if(d%7==0){
                cout<<"Sunday"<<endl;
            }else if(d%7==1){
                cout<<"Monday"<<endl;
            }else if(d%7==2){
                cout<<"Tuesday"<<endl;
            }else if(d%7==3){
                cout<<"Wednesday"<<endl;
            }
        }
        if(m==5){
            if(d%7==6){
                cout<<"Thursday"<<endl;
            }else if(d%7==0){
                cout<<"Friday"<<endl;
            }else if(d%7==1){
                cout<<"Saturday"<<endl;
            }else if(d%7==2){
                cout<<"Sunday"<<endl;
            }else if(d%7==3){
                cout<<"Monday"<<endl;
            }else if(d%7==4){
                cout<<"Tuesday"<<endl;
            }else if(d%7==5){
                cout<<"Wednesday"<<endl;
            }
        }
        if(m==6){
            if(d%7==3){
                cout<<"Thursday"<<endl;
            }else if(d%7==4){
                cout<<"Friday"<<endl;
            }else if(d%7==5){
                cout<<"Saturday"<<endl;
            }else if(d%7==6){
                cout<<"Sunday"<<endl;
            }else if(d%7==0){
                cout<<"Monday"<<endl;
            }else if(d%7==1){
                cout<<"Tuesday"<<endl;
            }else if(d%7==2){
                cout<<"Wednesday"<<endl;
            }
        }
        if(m==9||m==12){
            if(d%7==2){
                cout<<"Thursday"<<endl;
            }else if(d%7==3){
                cout<<"Friday"<<endl;
            }else if(d%7==4){
                cout<<"Saturday"<<endl;
            }else if(d%7==5){
                cout<<"Sunday"<<endl;
            }else if(d%7==6){
                cout<<"Monday"<<endl;
            }else if(d%7==0){
                cout<<"Tuesday"<<endl;
            }else if(d%7==1){
                cout<<"Wednesday"<<endl;
            }
        }
        if(m==10){
            if(d%7==0){
                cout<<"Thursday"<<endl;
            }else if(d%7==1){
                cout<<"Friday"<<endl;
            }else if(d%7==2){
                cout<<"Saturday"<<endl;
            }else if(d%7==3){
                cout<<"Sunday"<<endl;
            }else if(d%7==4){
                cout<<"Monday"<<endl;
            }else if(d%7==5){
                cout<<"Tuesday"<<endl;
            }else if(d%7==6){
                cout<<"Wednesday"<<endl;
            }
        }
        if(m==11){
            if(d%7==4){
                cout<<"Thursday"<<endl;
            }else if(d%7==5){
                cout<<"Friday"<<endl;
            }else if(d%7==6){
                cout<<"Saturday"<<endl;
            }else if(d%7==0){
                cout<<"Sunday"<<endl;
            }else if(d%7==1){
                cout<<"Monday"<<endl;
            }else if(d%7==2){
                cout<<"Tuesday"<<endl;
            }else if(d%7==3){
                cout<<"Wednesday"<<endl;
            }
        }
    }
    return 0;
}

C++: /*****include*****/
#include <iostream>
#include <fstream>
#include <string>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	int month_table[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
	int month;
	int date;
	int date_num;
	/*****処理部*****/
	while(1){
		cin >> month >> date;
		if(month == 0)	break;
		month--;	//配列の番号に合わせる
		date_num = 0;
		for(int i=0;i<month;i++)
			date_num += month_table[i];
		date_num += date;
		date_num = date_num % 7;
		switch(date_num){
		case 0:
			cout << "Wednesday" << endl;
			break;
		case 1:
			cout << "Thursday" << endl;
			break;
		case 2:
			cout << "Friday" << endl;
			break;
		case 3:
			cout << "Saturday" << endl;
			break;
		case 4:
			cout << "Sunday" << endl;
			break;
		case 5:
			cout << "Monday" << endl;
			break;
		case 6:
			cout << "Tuesday" << endl;
			break;
		}
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.wdt", "r", stdin);
	// 2004/01/01 is Thursday
	const string week[] = {
	"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
	const int days[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 
	string str = "";
	
	while (1){
		int month = 0;
		int day = 0;		
		cin >> month >> day;
		if (month == 0 && day == 0){
			break;
		} // end if
		int num = 0;
		for (int i = 0; i < month; ++i){
			num += days[i];
		} // end for
		num += day;
		cout << week [( num - 1 + 3 ) % 7 ] << endl;
	} // end while
		
	return 0;
}