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++: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
        string S; cin >> S;
        if (S == "#") break;
        int y,m,d; cin >> y >> m >> d;
        if (y > 31) {
            y -= 30;
            S = "?";
        } else if (y == 31 && m >= 5) {
            y = 1;
            S = "?";
        }

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

C++: #include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    while (true) {
        string s;
        int y, m, d;
        cin >> s;
        if (s[0] == '#') break;
        cin >> y >> m >> d;
        if (y > 31) {
            cout << "?" << " ";
            printf("%d %d %d\n", y-30, m, d);
        }
        else if (y == 31) {
            if (m >= 5) {
                cout << "?" << " ";
                printf("%d %d %d\n", y-30, m, d);
            }
            else {
                cout << "HEISEI" << " ";
                printf("%d %d %d\n", y, m, d);
            }
        }
        else {
            cout << "HEISEI" << " ";
            printf("%d %d %d\n", y, m, d);
        }
    }
    return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

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

C++: #include<bits/stdc++.h>
#define LL long long
#define REP(i, n) for(int i=0;i<(n);++i)
#define REPA(i, n) for(int i=1;i<(n);++i)
#define lp(i, n) for(int i=-;i<(n);++i)
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define DEKAI ((int)1e9+7)
#define ALL(x) (x).begin(), (x).end()
#define BIT(x) (1<<(x))
#define foreach(i, n) for(auto &i:(n))
using namespace std;

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

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

int main() {
	string S;
	while (cin >> S) {
		if (S == "#") return 0;
		int Y, M, D;
		cin >> Y >> M >> D;
		if (Y <= 30 || (Y == 31 && 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 g;
    int y, m, d;
    while (cin >> g) {
        if (g == "#") break;
        cin >> y >> m >> d;
        if (y < 31 || (y == 31 && m < 5)) {
            cout << g << " " << y << " " << m << " " << d << endl;
        } else {
            cout << "? " << (y-30) << " " << 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<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

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