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>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
 
void Main() {
  string s;
  while(cin >> s && s!="#") {
    int y,m,d;
    cin >> y >> m >> d;
    if(y<31) cout << s << " ";
    else if(y==31) {
      if(m<=4) cout << s << " ";
      else {
        cout << "?" << " ";
        y-=31;
        y++;
      }
    } else {
      cout << "?" << " ";
      y-=31;
      y++;
    }
    pr(y,m,d);
  }
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

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

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

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
  while (true) {
    string s;
    int y, m, d;
    cin >> s;
    if (s == "#")
      break;
    cin >> y >> m >> d;
    if (y > 31) {
      y -= 30;
      s = "?";
    } else if (y == 31 && m >= 5) {
      y -= 30;
      s = "?";
    }
    cout << s << " " << y << " " << m << " " << d << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    string s;
    int a, b, c;
    while (cin >> s)
    {
        if (s != "HEISEI")
            return 0;
        cin >> a >> b >> c;
        if (a >= 32 || (a == 31 && b >= 5))
        {
            printf("? %d %d %d\n", a - 30, b, c);
        }
        else
        {
            printf("HEISEI %d %d %d\n", a, b, c);
        }
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int y,m,d;
  string g;
  while(cin>>g&&g!="#"){
    cin>>y>>m>>d;
    if(y==31&&m>=5){
      g='?'; y-=30;
    }
    if(y>31){
      g='?'; y-=30;
    }
    cout<<g<<" "<<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 s;
    int y, m, d;
    while(cin >> s >> y >> m >> d){
        if(y < 31){
            cout << s << " " << y << " " << m << " " << d << endl;
        }else if(y > 31){
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        }else if(m <= 4){
            cout << s << " " << y << " " << m << " " << d << endl;
        }else{
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        }
    }
}

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

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

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 && d <= 30)){
            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;
}