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 <string>
using namespace std;

int main()
{
    string g;
    int y, m, d;
    while(true){
        cin >> g;
        if(g == "#") break;
        cin >> y >> m >> d;
        if(y >= 32 || (y >= 31 && m >= 5)){
            g = "?";
            y -= 30;
        }
        cout << g << " " << y << " " << m << " " << d << endl;
    }
}

C++: #include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"
#include "functional"
#include "stack"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, L, R, H, W;



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

	string s;
	getline(cin, s);
	while (s != "#") {
		int v[3] = {};
		int index = 0;
		//cout << s << endl;
		for (int i = 7; i < s.size(); i++) {
			//cout << i <<" "<<index<< endl;
			if (s[i] == ' ') {
				index++;
			}
			else {
				v[index] *= 10;
				v[index] += s[i] - '0';
			}
		}
		string ret;
		if (v[0] <= 30 || (v[0] == 31 && v[1] <= 4)) {
			ret += "HEISEI " + to_string(v[0]) + " " + to_string(v[1]) + " " + to_string(v[2]);
		}
		else {
			ret += "? " + to_string((v[0] - 30)) + " " + to_string(v[1]) + " " + to_string(v[2]);
		}
		cout << ret << endl;
		getline(cin, s);
	}
}

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

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

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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back

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

C++: #include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

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

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

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

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

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

using namespace std;

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

  while (true) {
    cin >> g;
    if (g == "#") {
      break;
    }
    cin >> y >> m >> d;

    if (y > 31 || (y == 31 && m >= 5)) {
      y -= 30;
      g = "?";
    }

    cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
  }
}

C++: #include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

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

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

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

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

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

string g; int y, m, d;

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

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

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

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

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

C++: #include<bits/stdc++.h>
using namespace std;
#define BIG 1000000007
#define ll long long int

int main(){
  int y,m,d;
  bool b;
  string s;
  while(1){
    cin>>s;
    if(s=="#") break;
    cin>>y>>m>>d;
    b=true;
    if(y>31) b=false;
    else if(y==31){
      if(m>4) b=false;
    }
    if(b) cout<<"HEISEI"<<" ";
    else cout<<"?"<<" ";
    if(b) cout<<y<<" "<<m<<" "<<d<<endl;
    else cout<<y-30<<" "<<m<<" "<<d<<endl;
  }
  return 0;
}