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 REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)

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

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

using namespace std;

int main(){
  string g;
  int y, m, d;


  while(1){
    cin >> g;
    if( g == "#" ) break;

    scanf("%d %d %d", &y, &m, &d);

    if(y >= 32){
      y -= 30;
      printf("? %d %d %d\n",  y, m, d);
    }
    else if(y == 31 && m >= 5){
      printf("? 1  %d %d\n",  m, d);
    }
    else
      printf("HEISEI %d %d %d\n", y, m, d);
  }
  return 0;
}

C++: #include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 998244353;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

//入出力高速化(非同期化)
void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

string solve() {
    int y, m, d;
    cin >> y >> m >> d;
    string ret;
    if (y <= 31 && m < 5) {
        ret = "HEISEI ";
        ret += to_string(y);
        ret += " ";
        ret += to_string(m);
        ret += " ";
        ret += to_string(d);
    } else {
        ret += "?";
        ret += " ";
        ret += to_string(y-30);
        ret += " ";
        ret += to_string(m);
        ret += " ";
        ret += to_string(d);
    }
    return ret;
}

int main(){
    vector<string> ans;
    while (1) {
        string nengo;
        cin >> nengo;
        if (nengo == "HEISEI") ans.push_back(solve());
        else break;
    }
    for (auto &i: ans) {
        cout << i << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>

using namespace std;

int main(){
	char dm[7];
	int y,m,d;
	while(1){
		scanf("%s",dm);
		if(dm[0]=='#')
		break;
		scanf("%d %d %d",&y,&m,&d);
		if(y<=31){
			if(y==31&&m>=5)
			printf("? 1 %d %d\n",m,d);
			else
			printf("HEISEI %d %d %d\n",y,m,d);
		}
		else{
			printf("? %d %d %d\n",y-31+1,m,d);
		}
	}
}

C++: #include <iostream>
using namespace std;
int main(){
  string s;
  while(cin >> s, s != "#"){
    int y, m, d;
    cin >> y >> m >> d;
    if(y < 31) cout << s << " " << y << " " << m << " " << d << endl;
    else if(y > 31 || m > 4) cout << "? " << y-30 << " " << m << " " << d << endl;
    else cout << s << " " << y << " " << m << " " << d << endl;
  }
  return 0;
}

C++: //#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <climits>

using namespace std;
using ll=long long;

void solve(){
  while(true){
    string str;
    cin >> str;
    if(str=="#")return;
    int y,m,d;
    cin >> y >> m >> d;
    if(y<31||(y==31&&m<5))
      cout << "HEISEI " << y << " " << m << " " << d << endl;
    else
      cout << "? " << y-30 << " " << m << " " << d << endl;
    
    

  }
}

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

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
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 V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string g; int y,m,d;
    while(true){
        cin >> g;
        if(g == "#") break;
        cin >> y >> m >> d;
        if(y <= 30 || (y == 31 && m <= 4)){
            cout << "HEISEI " << y << " " << m << " " << d << endl;
        }else{
            cout << "? " << y-30 << " " << m << " " << d << endl;
        }
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    //cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}

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

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