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++: #define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
	while (true) {
		int b, c, d;;
		string s;
		cin >> s;
		if (s == "#") return;
		cin >> b >> c >> d;
		int kaigen = 0;
		if (b > 31) {
			kaigen = 1;
		}
		if (b == 31 && c >= 5) {
			kaigen = 1;
		}
		if (kaigen == 1) {
			b -= 30;
			cout << "?";
		}
		else {
			cout << "HEISEI";
		}
		cout << " " << b << " " << c << " " << d << endl;
	}
}
#undef int

int main() {
	init();
	solve();
}

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

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

C++: #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

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

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

using namespace std;

int main(void){

  string g;
  int y,m,d;

  while(cin >> g){

    if(g=="#")
      break;

    cin >> y >> m >> d;

    if(y > 31){
      y=y-30;
      g="?";
    }

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

  return 0;
}

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

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

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	string s; int y, m, d;
	while (cin >> s, s != "#") {
		cin >> y >> m >> d;
		d += m * 100;
		if (y > 31 ||(y == 31 && d > 500)) cout << "? " << y - 30;
		else cout << "HEISEI " << y;
		cout << ' ' << m << ' ' << d % 100 << endl;
	}
}

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<bits/stdc++.h> 
using namespace std;

int main(){
	string a;
	while(cin>>a){
		if(a[0]=='#')break;
		int b,c,d;
		cin>>b>>c>>d;
		if(b<31)cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		else if(b==31 &&  c<5)cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		else{
		b-=30;
		a = "?";
		cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		}

	}
	return 0;
}

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

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

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

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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  if (stream2 == NULL) return 0;
#endif
  string s;
  while (cin >> s) {
    if (s == "#") break;
    int a, b, c; cin >> a >> b >> c;
    pair<pair<int,int> ,int> p = make_pair(make_pair(a, b), c);
    pair<pair<int,int> ,int> q = make_pair(make_pair(31, 4), 30);
    if (p > q) {
      cout << "? " << a - 30 << " " << b << " " << c << endl;
    } else {
      cout << "HEISEI " << a << " " << b << " " << c << endl;
    }
  }
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  fclose(stream2);
#endif
  return 0;
}