Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

//ConvReiwa ..
func ConvReiwa(sd []string) []string {
	var ne []string
	yr, _ := strconv.Atoi(sd[1])
	mn, _ := strconv.Atoi(sd[2])

	switch {
	case yr < 31:
		return sd
	case yr == 31 && mn < 5:
		return sd
	default:
		ne = append(ne, "?")
		ne = append(ne, strconv.Itoa(yr-30))
		ne = append(ne, sd[2])
		ne = append(ne, sd[3])
		return ne
	}
}

func main() {

	for sc.Scan() {

		str := sc.Text()

		if str == "#" {
			break
		}

		sdt := strings.Split(str, " ")
		ans := ConvReiwa(sdt)

		fmt.Printf("%s %s %s %s\n", ans[0], ans[1], ans[2], ans[3])
	}

}

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

typedef long long ll;

int main(){
    string s;
    int a,b,c;
    while(cin >> s && s!="#"){
        cin >> a >> b >> c;
        int x = 400*a+40*b+c;
        if(x>=400*31+40*5+1){
            s = "?";
            a-=30;
        }
        cout << s << " " << a << " " << b << " " << c << endl;
    }
    return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1275
//ヨセフスの問題 ブログを書きましょう！！
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
int main(void)
{
    string s;
    int y, m, d;
    while (cin >> s >> y >> m >> d)
    {
        if (s == "#")
            break;

        if ((y == 31 && m >= 5) || y >= 32)
        {
            y -= 30;
            s = "?";
        }
        cout << s << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int y, m, d;
	string g;
	while(cin >> g && g != "#"){
		cin >> y >> m >> d;
		if(y == 31){
			if(m < 5){
				cout << "HEISEI" << " " << y << " " << m << " " << d << endl;
			} else {
				cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
			}
		} else if(y < 31){
			cout << "HEISEI" << " " << y << " " << m << " " << d << endl;
		} else {
			cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
		}
	}

	return 0;
}

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

int main() {
    string s;
    while (cin >> s, s != "#") {
        int y, m, d; cin >> y >> m >> d;

        if (y > 31 || (y == 31 && m > 4)) {
            cout << "? " << y-30;
        } else {
            cout << s << " " << y;
        }
        cout << " " << m << " " << d << endl;
    }
}

C++: #include <iostream>
#include <utility>
#include <string>

using namespace std;

string s;
int y, m, d;

int main(void)
{
	while(1){
		cin >> s;
		if(s == "#") break;
		cin >> y >> m >> d;
		
		if(make_pair(y, make_pair(m, d)) > make_pair(30, make_pair(4, 30))){
			s = "?", y -= 30;
		}
		cout << s << " " << y << " " << m << " " << d << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){

    while(1){
        string s; cin >> s;
        if(s == "#") break;
        int y, m, d; cin >> y >> m >> d;
        string ans;
        if(y <= 30) ans = "HEISEI";
        else if(y >= 32){
            ans = "?";
            y -= 30
        }
        else{
            if(m <= 4) ans = "HEISEI";
            else{
                ans = "?";
                y -= 30;
            }
        }

        cout << ans << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}

C++: #include <iostream>


using namespace std;

int main(){
    string geng[100];
    int nen[100],getu[100],day[100];
    int i = 0;
    cin >> geng[i];
    while(geng[i] != "#"){
        cin >> nen[i] >> getu[i] >> day[i];
        if(nen[i] >= 32){
            cout << '?' << ' ' << nen[i] - 30 << ' ' << getu[i] << ' ' << day[i] << endl;
        }else{
            if(nen[i] == 31 && getu[i] >= 5){
                cout << '?' << ' ' << nen[i] - 30 << ' ' << getu[i] << ' ' << day[i] << endl;
            }else{
                cout << "HEISEI" << ' ' << nen[i] << ' ' << getu[i] << ' ' << day[i] << endl;
            }
        }
        i++;
        cin >> geng[i];
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define FOR(i,s,t) for(int i = s ; i < t ; i++)

int main() {

	string s;
	while (cin >> s) {
		if (s == "#")break;
		int y, m, d; cin >> y >> m >> d;
		bool ok = 0;
		if (y < 31 || (y == 31 && m <= 4)) {
			ok = 1;
		}
		else {
			y -= 30;
		}


		if (ok) {
			cout << "HEISEI" << " " << y << " " << m << " " << d << endl;
		}
		else {
			cout << "?" << " " << y << " " << m << " " << d << endl;
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){

    while(1){
        string s; cin >> s;
        if(s == "#") break;
        int y, m, d; cin >> y >> m >> d;
        string ans;
        if(y <= 30) ans = "HEISEI";
        else if(y >= 32){
            ans = "?";
            y -= 30
        }
        else{
            if(m <= 4) ans = "HEISEI";
            else{
                ans = "?";
                y -= 30;
            }
        }

        cout << ans << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	string str;
	int y,m,d;
	while(cin >> str,str[0] != '#'){
		cin >> y >> m >> d;
		if(y > 31 || (y == 31 && m >= 5)){
			cout << '?' << ' ' << y - 30 << ' ' << m << ' ' << d << endl;
		}
		else{
			cout << str << ' ' << y << ' ' << m << ' ' << d << endl;
		}
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

string era;
int y,m,d;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> era,era!="#"){
        cin >> y >> m >> d;
        if (y==31&&4<m||31<y) era="?",y-=30;
        cout << era << ' ' << y << ' ' << m << ' ' << d << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    while (cin >> s, s != "#") {
        int y, m, d;
        cin >> y >> m >> d;

        if (y > 31) {
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        } else if (m >= 5) {
            cout << "? 1 " << m << " " << d << endl;
        } else {
            cout << s << " " << y << " " << m << " " << d << endl;
        }
    }

    return 0;
}