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 m,d;
	while(1){
		cin>>m>>d;
		if(m==0||d==0) break;
			  if(m==1&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Thursday"<<endl;
		}else if(m==1&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Friday"<<endl;
		}else if(m==1&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Saturday"<<endl;
		}else if(m==1&&(d==4||d==11||d==18||d==25)){
			cout<<"Sunday"<<endl;
		}else if(m==1&&(d==5||d==12||d==19||d==26)){
			cout<<"Monday"<<endl;
		}else if(m==1&&(d==6||d==13||d==20||d==27)){
			cout<<"Tuesday"<<endl;
		}else if(m==1&&(d==7||d==14||d==21||d==28)){
			cout<<"Wednesday"<<endl;
		}else if(m==2&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Sunday"<<endl;
		}else if(m==2&&(d==2||d==9||d==16||d==23)){
			cout<<"Monday"<<endl;
		}else if(m==2&&(d==3||d==10||d==17||d==24)){
			cout<<"Tuesday"<<endl;
		}else if(m==2&&(d==4||d==11||d==18||d==25)){
			cout<<"Wednesday"<<endl;
		}else if(m==2&&(d==5||d==12||d==19||d==26)){
			cout<<"Thursday"<<endl;
		}else if(m==2&&(d==6||d==13||d==20||d==27)){
			cout<<"Friday"<<endl;
		}else if(m==2&&(d==7||d==14||d==21||d==28)){
			cout<<"Saturday"<<endl;
		}else if(m==3&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Sunday"<<endl;
		}else if(m==3&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Monday"<<endl;
		}else if(m==3&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Tuesday"<<endl;
		}else if(m==3&&(d==4||d==11||d==18||d==25)){
			cout<<"Wednesday"<<endl;
		}else if(m==3&&(d==5||d==12||d==19||d==26)){
			cout<<"Thursday"<<endl;
		}else if(m==3&&(d==6||d==13||d==20||d==27)){
			cout<<"Friday"<<endl;
		}else if(m==3&&(d==7||d==14||d==21||d==28)){
			cout<<"Saturday"<<endl;
		}else if(m==4&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Wednesday"<<endl;
		}else if(m==4&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Thursday"<<endl;
		}else if(m==4&&(d==3||d==10||d==17||d==24)){
			cout<<"Friday"<<endl;
		}else if(m==4&&(d==4||d==11||d==18||d==25)){
			cout<<"Saturday"<<endl;
		}else if(m==4&&(d==5||d==12||d==19||d==26)){
			cout<<"Sunday"<<endl;
		}else if(m==4&&(d==6||d==13||d==20||d==27)){
			cout<<"Monday"<<endl;
		}else if(m==4&&(d==7||d==14||d==21||d==28)){
			cout<<"Tuesday"<<endl;
		}else if(m==5&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Friday"<<endl;
		}else if(m==5&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Saturday"<<endl;
		}else if(m==5&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Sunday"<<endl;
		}else if(m==5&&(d==4||d==11||d==18||d==25)){
			cout<<"Monday"<<endl;
		}else if(m==5&&(d==5||d==12||d==19||d==26)){
			cout<<"Tuesday"<<endl;
		}else if(m==5&&(d==6||d==13||d==20||d==27)){
			cout<<"Wednesday"<<endl;
		}else if(m==5&&(d==7||d==14||d==21||d==28)){
			cout<<"Thursday"<<endl;
		}else if(m==6&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Monday"<<endl;
		}else if(m==6&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Tuesday"<<endl;
		}else if(m==6&&(d==3||d==10||d==17||d==24)){
			cout<<"Wednesday"<<endl;
		}else if(m==6&&(d==4||d==11||d==18||d==25)){
			cout<<"Thursday"<<endl;
		}else if(m==6&&(d==5||d==12||d==19||d==26)){
			cout<<"Friday"<<endl;
		}else if(m==6&&(d==6||d==13||d==20||d==27)){
			cout<<"Saturday"<<endl;
		}else if(m==6&&(d==7||d==14||d==21||d==28)){
			cout<<"Sunday"<<endl;
		}else if(m==7&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Wednesday"<<endl;
		}else if(m==7&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Thursday"<<endl;
		}else if(m==7&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Friday"<<endl;
		}else if(m==7&&(d==4||d==11||d==18||d==25)){
			cout<<"Saturday"<<endl;
		}else if(m==7&&(d==5||d==12||d==19||d==26)){
			cout<<"Sunday"<<endl;
		}else if(m==7&&(d==6||d==13||d==20||d==27)){
			cout<<"Monday"<<endl;
		}else if(m==7&&(d==7||d==14||d==21||d==28)){
			cout<<"Tuesday"<<endl;
		}else if(m==8&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Saturday"<<endl;
		}else if(m==8&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Sunday"<<endl;
		}else if(m==8&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Monday"<<endl;
		}else if(m==8&&(d==4||d==11||d==18||d==25)){
			cout<<"Tuesday"<<endl;
		}else if(m==8&&(d==5||d==12||d==19||d==26)){
			cout<<"Wednesday"<<endl;
		}else if(m==8&&(d==6||d==13||d==20||d==27)){
			cout<<"Thursday"<<endl;
		}else if(m==8&&(d==7||d==14||d==21||d==28)){
			cout<<"Friday"<<endl;
		}else if(m==9&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Tuesday"<<endl;
		}else if(m==9&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Wednesday"<<endl;
		}else if(m==9&&(d==3||d==10||d==17||d==24)){
			cout<<"Thursday"<<endl;
		}else if(m==9&&(d==4||d==11||d==18||d==25)){
			cout<<"Friday"<<endl;
		}else if(m==9&&(d==5||d==12||d==19||d==26)){
			cout<<"Saturday"<<endl;
		}else if(m==9&&(d==6||d==13||d==20||d==27)){
			cout<<"Sunday"<<endl;
		}else if(m==9&&(d==7||d==14||d==21||d==28)){
			cout<<"Monday"<<endl;
		}else if(m==10&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Thursday"<<endl;
		}else if(m==10&&(d==2||d==9||d==16||d==23||d||30)){
			cout<<"Friday"<<endl;
		}else if(m==10&&(d==3||d==10||d==17||d==24||d==31)){
			cout<<"Saturday"<<endl;
		}else if(m==10&&(d==4||d==11||d==18||d==25)){
			cout<<"Sunday"<<endl;
		}else if(m==10&&(d==5||d==12||d==19||d==26)){
			cout<<"Monday"<<endl;
		}else if(m==10&&(d==6||d==13||d==20||d==27)){
			cout<<"Tuesday"<<endl;
		}else if(m==10&&(d==7||d==14||d==21||d==28)){
			cout<<"Wednesday"<<endl;
		}else if(m==11&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Sunday"<<endl;
		}else if(m==11&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Monday"<<endl;
		}else if(m==11&&(d==3||d==10||d==17||d==24)){
			cout<<"Tuesday"<<endl;
		}else if(m==11&&(d==4||d==11||d==18||d==25)){
			cout<<"Wednesday"<<endl;
		}else if(m==11&&(d==5||d==12||d==19||d==26)){
			cout<<"Thursday"<<endl;
		}else if(m==11&&(d==6||d==13||d==20||d==27)){
			cout<<"Friday"<<endl;
		}else if(m==11&&(d==7||d==14||d==21||d==28)){
			cout<<"Saturday"<<endl;
		}else if(m==12&&(d==1||d==8||d==15||d==22||d==29)){
			cout<<"Tuesday"<<endl;
		}else if(m==12&&(d==2||d==9||d==16||d==23||d==30)){
			cout<<"Wednesday"<<endl;
		}else if(m==12&&(d==3||d==10||d==17||d==24||d||31)){
			cout<<"Thursday"<<endl;
		}else if(m==12&&(d==4||d==11||d==18||d==25)){
			cout<<"Friday"<<endl;
		}else if(m==12&&(d==5||d==12||d==19||d==26)){
			cout<<"Saturday"<<endl;
		}else if(m==12&&(d==6||d==13||d==20||d==27)){
			cout<<"Sunday"<<endl;
		}else if(m==12&&(d==7||d==14||d==21||d==28)){
			cout<<"Monday"<<endl;
		}
	}
}