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 <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    string s;
    int y,m,d;
    while(1){
        cin>>s;
        if(s=="#")break;
        cin>>y>>m>>d;
        if(y>31||(y==31&&m>=5)){
            cout<<"?"<<" "<<y-30<<" "<<m<<" "<<d<<endl;
        }
        else{
            cout<<s<<" "<<y<<" "<<m<<" "<<d<<endl;
        }
    }

    
//////////////////////////////////////////////////////
return 0;}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

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

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

int main(int argc, char const *argv[])
{
	string s;
	while(cin>>s,s!="#")
	{
		int a,b,c;
		cin>>a>>b>>c;
		if(a>31||(a==31&&b>=5)) s="?",a-=30;
		cout<<s<<" "<<a<<" "<<b<<" "<<c<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

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

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

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

C++: #include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <map>

using namespace std;

int solve(){
    int year,month, day;
    vector<string> reiwa;
    cin>>year>>month>>day;
    if(year > 31){
        // reiwa.push_back("?");
        // reiwa.push_back(sprintf(year-30));
        cout<<"? "<<year-30<< " "<<month<<" "<<day<<endl;
            return 0;
    }else if(year == 31){
        if(month >= 5){
            // reiwa.push_back("?");
            // string s = (string)(year-30);
            // reiwa.push_back(sprintf(year-30));
            cout<<"? "<<year-30<< " "<<month<<" "<<day<<endl;
            return 0;
        }
        else {
            // reiwa.push_back("HEISEI");
            // reiwa.push_back(sprintf(year));
            cout<<"HEISEI "<<year<< " "<<month<<" "<<day<<endl;
            return 0;
        }
    }else{
        //  reiwa.push_back("HEISEI");
        //  reiwa.push_back(sprintf(year));
        cout<<"HEISEI "<<year<< " "<<month<<" "<<day<<endl;
        return 0;
    }
    // reiwa.push_back(sprintf(month));
    // reiwa.push_back(sprintf(day));
    // return reiwa;
}

int main(){
    string heisei;
    vector<vector<string>> ans;
    while(1){
        cin>>heisei;
        if(heisei == "#")break;
        // ans.push_back(solve());
        solve();
    }

    // for(int i = 0;i < ans.size(); i++){
    //     cout<<ans[i][0] << " "<<ans[i][1] << " "<<ans[i][2] <<" "<<ans[i][3]<<endl;
    // }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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


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



	return 0;
}