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 <bits/stdc++.h>
using namespace std;

const string day[] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};
const int da[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main(void){
  int m, d;
  while(cin >> m >> d, m | d){
    while(1){
      m--;
      if(m > 0){
        d += da[m];
      }else{
        break;
      }
    }
    cout << day[d%7] << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

int solve(int m, int d) {
	int y = 2004;
	if (m <= 2) {
		m += 12;
		y--; 
	}
	return (y + y / 4 - y / 100 + y / 400 + (13 * m + 8) / 5 + d) % 7;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int m, d;
	while (cin >> m >> d) {
		if (m == 0 && d == 0) break;

		switch (solve(m, d)) {
			case 0:
				cout << "Sunday" << endl;
				break;
			case 1:
				cout << "Monday" << endl;
				break;
			case 2:
				cout << "Tuesday" << endl;
				break;
			case 3:
				cout << "Wednesday" << endl;
				break;
			case 4:
				cout << "Thursday" << endl;
				break;
			case 5:
				cout << "Friday" << endl;
				break;
			case 6:
				cout << "Saturday" << endl;
				break;
		}
	}
	return 0;
}

C++: # include <iostream>
using namespace std;
int main(){
    int month,day,sum;
    cin >> month >> day;
    while(month != 0){
        sum = 0;
        switch(month){
            case 1: sum = day; break;
            case 2: sum = 31+day; break;
            case 3: sum = 60+day; break;
            case 4: sum = 91+day; break;
            case 5: sum = 121 + day;break;
            case 6: sum = 152 + day;break;
            case 7: sum = 182 +day;break;
            case 8: sum = 213 + day;break;
            case 9: sum = 244 +day;break;
            case 10: sum = 274 +day;break;
            case 11: sum = 305 + day;break;
            case 12: sum = 335 +day;break;
            }
            sum %= 7;
        switch(sum){
            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;
            case 0: cout << "Wednesday" << endl ;break;
        }
        cin >> month >> day;
        }
}

C++: #include <bits/stdc++.h>

using namespace std;

int zeller(int M,int D,int Y = 2004){
  if(M < 3){
    Y--;
    M += 12;
  }
  return (Y+Y/4-Y/100+Y/400+(13*M+8)/5+D)%7;
}

int main(){
  int M,D;
  string A[7] = {"Sunday",
                 "Monday",
                 "Tuesday",
                 "Wednesday",
                 "Thursday",
                 "Friday",
                 "Saturday"};

  while(cin >> M >> D,M){
    cout << A[zeller(M,D)] << endl;
  }
}

C++: #include<iostream>

using namespace std;

int main()
{
	for(;;){
		int month;
		int day;
		int flg;
		int i;
		
		int past = 0;
		
		cin >> month;
		cin >> day;
		
		if(month == 0 && day == 0){
			break;
		}
		
		
	//	cout << month << day << endl;
		
		
		for(i = 0; i < month-1; i++){
			if(i == 1){
				past+=29;
			}
			else if(i == 0 || i == 2 || i == 4 || i == 6 || i == 7 || i == 9|| i == 11){
				past += 31;
			}
			else{
				past += 30;
			}
		}
		
		past += day-1;
		past%=7;
		
		switch(past){
			case 0:
				cout << "Thursday" << endl;
				break;
			case 1:
				cout << "Friday" << endl;
				break;
			case 2:
				cout << "Saturday" << endl;
				break;
			case 3:
				cout << "Sunday" << endl;
				break;
			case 4:
				cout << "Monday" << endl;
				break;
			case 5:
				cout << "Tuesday" << endl;
				break;
			case 6:
				cout << "Wednesday" << endl;
				break;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int main()
{
	int m, d;
	while(1){
		int ds = 0;
		cin >> m >> d;
		if(m == 0){
			break;
		}
		for (int i = 1; i < m; ++i)
		{
			if(i == 4 || i == 6 || i == 9 || i == 11){
				ds += 30;
			}else if(i == 2){
				ds += 29;
			}else{
				ds += 31;
			}
		}
		ds += d;
		//cerr << ds << endl;
		ds %= 7;
		switch(ds){
			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;
			case 0:
			cout << "Wednesday" << endl;
			break;
		}
	}
	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, day;		
//		stringstream ss(str);
//		ss >> month >> day;
		cin >> month >> day;
		if (month == 0 && day == 0){
			break;
		} // end if
		int num = 0;
		int i;
		for (i = 0; i < month; ++i){
			num += days[i];
		} // end for
		num += day;
//		cout << "num: " << num << endl;
		cout << week [( num - 1 ) % 7 + 3 ] << endl;
	} // end while
		
	return 0;
}