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>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
        string s;
        int y, m, d;
        while(cin>>s && s!="#"){
                scanf("%d%d%d", &y, &m, &d);
                if((y==31 && m>=5) || y>31) s="?", y-=30;
                cout << s << " ";
                printf("%d %d %d\n", y, m, d);
        }
}

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;
        if(y > 31 || (y == 31 && m >= 5)){
            printf("? %d %d %d\n", y - 30, m, d);
        } else {
            printf("HEISEI %d %d %d\n", y, m, d);
        }
    }
    return 0;
}

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

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

        string ans = "HEISEI";
        if(y>31 || (y==31 && m>4)){
            y -= 30;
            ans = "?";
        }

        cout << ans << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

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 U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	while (S != "#") {
		int y, m, d;
		cin >> y >> m >> d;
		if (y >= 32 || (y == 31 && m > 4)) {
			y -= 30;
			printf("? %d %d %d\n", y, m, d);
		}
		else {
			printf("%s %d %d %d\n", S.c_str(), y, m, d);
		}
		cin >> S;
	}
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

ll y, m, d;
string g;

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

C++: #include<stdio.h>
int main()
{
	char g[7];
	int y,m,d;
	while(1){
		scanf("%s",g);
		if(g[0]=='#'){
			break;
		}
		scanf("%d %d %d",&y,&m,&d);
		if(y<31){
			printf("HEISEI %d %d %d\n",y,m,d);
		}else if(y==31){
			if(m<=4){
				printf("HEISEI %d %d %d\n",y,m,d);
			}else{
				printf("? %d %d %d\n",y-30,m,d);
			}
		}else{
			printf("? %d %d %d\n",y-30,m,d);
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const string space=" ";
int main(){
	while(1){
		string g;
		int y,m,d;
		cin>>g;
		if(g=="#")break;
		cin>>y>>m>>d;
		if(y>31||y==31&&m>4){
			g="?";
			y-=30;
		}
		cout<<g<<space<<y<<space<<m<<space<<d<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


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

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

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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