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 FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {if (a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmin(A &a, B b) {if (a > b) {a = b; return 1;} return 0;}
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const bool debug = 0;
/****************************/

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=100005,INF=1<<28;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        string S;
        int A,B,C;cin>>S>>A>>B>>C;
        
        if(S=="#") break;
        
        if(A==31){
            if(B<=4){
                cout<<"HEISEI "<<A<<" "<<B<<" "<<C<<endl;
            }else{
                cout<<"? "<<1<<" "<<B<<" "<<C<<endl;
            }
        }else if(A<31){
            cout<<"HEISEI "<<A<<" "<<B<<" "<<C<<endl;
        }else{
            cout<<"? "<<A-30<<" "<<B<<" "<<C<<endl;
        }
    }
}

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

int main(){

    string g;
    int y, m, d;
    while(cin >> g){
        if(g=="#")break;
        cin >> y >> m >> d;
        int hoge = y * 10000 + m * 100 + d;
        if(hoge > 310430){
            cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
        }
        else{
            cout << g << " " << y << " " << m << " " << d << endl;
        }
    }


    return 0;
}

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

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
int main(){
    string g;
    string s = "?";
    int y,m,d;
    while(1){
        cin >> g;
        if(g=="#") return 0;

        cin >> y >> m >> d;

        if(y>=31){
            if(y==31&&m>=5){
                cout << s << " " << y-30 << " " << m << " " << d << endl;
            }else if(y>=32){
                cout << s << " " << y-30 << " " << m << " " << d << endl;
            }else{
                cout << g << " " << y << " " << m << " " << d << endl;
            }
        }else{
            cout << g << " " << y << " " << m << " " << d << endl;
        }
    }

}

C++: #include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for(long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for(long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                                                            \
    (upper_bound((V).begin(), (V).end(), X) -                                  \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                                                               \
    {                                                                          \
        cerr << #v << ':';                                                     \
        for(auto xv : v) cerr << xv << ' ';                                    \
        cerr << endl;                                                          \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T &a, const T &b) {
    if(a > b) a = b;
    return a > b;
}
template <typename T> inline bool chmax(T &a, const T &b) {
    if(a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    string g;
    while(true) {
        cin >> g;
        if(g == "#") return 0;
        int y, m, d;
        cin >> y >> m >> d;
        if(make_tuple(31, 5, 1) <= make_tuple(y, m, d)) {
            cout << "? " << y - 30 << ' ' << m << ' ' << d << endl;
        } else {
            cout << "HEISEI " << y << ' ' << m << ' ' << d << endl;
        }
    }
}

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

using namespace std;

int main(){
  string g[100];
  int y[100], m[100], d[100];
  int cnt_in = 0;

  for(;;){
    cin >> g[cnt_in];
    if(g[cnt_in] == "#"){
      break;
    }

    cin >> y[cnt_in] >> m[cnt_in] >> d[cnt_in];
    cnt_in++;
  }

  for(int i = 0; i < cnt_in; i++){
    if((y[i] > 31) || (y[i] == 31) && (m[i] >= 5)){
      cout << "?" << " " << y[i] - 30 << " " << m[i] << " " << d[i] << endl;
    }
    else{
      cout << g[i] << " " << y[i] << " " << m[i] << " " << d[i] << endl;
    }
  }

  return 0;
}

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

int main(){
  string s;
  int g,m,d;
  bool flg;
  while(1){
    flg=false;
    cin>>s;
    if(s=="#") break;
    cin>>g>>m>>d;
    if(g>=32){
      flg=true;
    }
    if(g>=31&&m>=5){
      flg=true;
    }
    if(flg){
      s="?";
      g-=30;
    }
    cout<<s<<" "<<g<<" "<<m<<" "<<d<<endl;
  }
  return 0;
}