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 <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    while (true) {
        string s; cin >> s;
        if (s=="#") break;
        int y, m, d; cin >> y >> m >> d;

        string ret;
        if (y>31 || (y==31&&m>=5)) {
            ret+="? ";
            y-=30;
        }
        else ret+="HEISEI ";

        cout << ret << y << " " << m << " " << d << endl;
    }
}

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

int main(){
    while (1) {
        string str;
        cin>>str;
        if("#"==str){
            break;
        }
        int y,m,d;
        cin>>y>>m>>d;
        if(y > 31 || y == 31 && m >= 5){
            std::cout<<"? "<<y-30<<" "<<m<<" "<<d<<endl;
        }else{
            std::cout<<str<<" "<<y<<" "<<m<<" "<<d<<endl;
        }
    }
}

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

#include <iostream>
#include <vector>
// #include <map>
#include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

struct Wareki {
	string g;
	int y;
	int m;
	int d;

	explicit Wareki() {};
	explicit Wareki(string g, int y, int m, int d) : g(g), y(y), m(m), d(d) {};
	void print() {
		cout << g << " " << y << " " << m << " " << d << endl;
	}
	Wareki convert() {
		Wareki converted;
		converted.g = g;
		converted.y = y;
		converted.m = m;
		converted.d = d;
		if ((y == 31 and m >= 5) or y > 31) {
			converted.g = "?";
			converted.y = y - 30;
		}
		return converted;
	}
};

int main() {
	string g;
	int y, m, d;

	while (1) {
		cin >> g >> y >> m >> d;
		if (g == "#") {
			break;
		}
		Wareki before(g, y, m, d);
		Wareki after = before.convert();
		after.print();
	}

	// std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

struct TWO{
    long long int a,b;
};

bool cmp(TWO x,TWO y){
    if(x.a!=y.a){
        return x.a<y.a;
    }else{
        return x.b<y.b;
    }
}

int main() {
    const long long int mod = 1000000007,INF=50000000000000;
    typedef pair<long long int,long long int>P;
	map<long long int, long long int>mp;
    priority_queue<P,vector<P>,greater<P> >mazuisushi;
    
    priority_queue<P>umaisushi;
	cout << fixed << setprecision(10);
    string str;
    long long int y,m,d;

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

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

int main() {
	string g;
	while (cin >> g, g != "#") {
		int y, m, d;
		cin >> y >> m >> d;
		if (10000 * y + m * 100 + d < 310501) cout << g << ' ' << y << ' ' << m << ' ' << d;
		else cout << '?' << ' ' << y - 30 << ' ' << m << ' ' << d;
		cout << endl;
	}
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string g; int y,m,d;
    while(true){
        cin >> g;
        if(g == "#") break;
        cin >> y >> m >> d;
        if(y <= 30 || (y == 31 && m <= 4){
            cout << "HEISEI " << y << " " << m << " " << d << endl;
        }else{
            cout << "? " << y-30 << " " << m << " " << d << endl;
        }
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    //cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}

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

int main(){

    while(1){
        string g; int y,m,d;

        cin>>g;

        if( g == "#") break;

        cin>>y>>m>>d;



        if(y == 31 && m >= 5){

            cout<<'?'<<" "<<y-30<<" "<<m<<" "<<d<<endl;
        }

        else if( y > 31){

            cout<<'?'<<" "<<y-30<<" "<<m<< " "<<d<<endl;
        }

        else cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;


    }

    return 0;
}