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 ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

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

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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int main(void){

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

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

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

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int y, m, d;

void HtoR()
{
    if (y > 30 || (y == 30 && m >= 5)) {
        cout<<"? "<<y - 30<<" "<<m<<" "<<d<<endl;
    } else {
        cout<<"HEISEI "<<y<<" "<<m<<" "<<d<<endl;
    }
}

int main()
{
    string g;
    while (cin>>g, g != "#") {
        cin>>y>>m>>d;
        if (g == "HEISEI") HtoR();
        else exit(1);
    }
}

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

using namespace std;

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

C++: #include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    string g;
    int y,m,d;
    while(cin >> g >> y >> m >> d,g != "#"){
        cout << ( y <= 30 or (y == 31 and ((m == 4 and d <= 30) or m < 4))? "HEISEI " + to_string(y) : "? " + to_string(y -30)) << " "<< m << " " << d << endl;
    }
}

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

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

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

    return 0;
}