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;

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

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

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

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 || 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;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while (cin >> s && s != "#") {
		int64 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);
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;

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

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

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

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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(){
while(1){
  string s{};int y,m,d;
  cin>>s;
  if(s=="#")return 0;
  cin>>y>>m>>d;
  if(y>31){
	  cout<<'?'<<" ";
	  y-=30;
  }
  else if(y==31){
	  if(m>=5){
		  cout<<'?'<<" ";
		  y-=30;
	  }
	  else cout<<s<<" ";
  }
  else cout<<s<<" ";
  cout<<y<<" "<<m<<" "<<d<<endl;
}
}

C++: #include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

string g;
int y, m, d;

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