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 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;
	}
	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 > 4)) {
			cout << "? " << y - 30 << " " << m << " " << d << endl;
		}
		else cout << g << " " << y << " " << m << " " << d << endl;
	}
	return 0;
}

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

string s;
int y,m,d;

int main(){
  int i,j;
  bool ch =0;
  while(1){
    cin >> s;
    if(s=="#")break;
    ch = 0;
    cin >> y >> m >> d;
    if(y>31)ch=1;
    else if(y==31&&m>4)ch=1;
    if(ch==1)cout << "? " <<y-30 <<" "<< m <<" " << d<<endl;
    else cout << s <<" " << y << " " << m << " " << d<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
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>4)){
			g = "?";
			y -= 30;
		}
		cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
	} 
	return 0;
}

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

using namespace std;

using lint = long long;
using ldouble = long double;

bool solve() {
    string S;
    cin >> S;
    if (S == "#") return false;

    int Y, M, D;
    cin >> Y >> M >> D;

    if (Y > 31 || (Y == 31 && M > 4)) {
        S = "?";
        Y -= 30;
    }

    cout << S << " " << Y << " " << M << " " << D << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}

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

using namespace std;
using ll = long long int;
#define long ll

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

    while(1) {
        string s;
        cin >> s;
        if(s == "#") break;
        ll y, m, d;
        cin >> y >> m >> d;
        if((y == 31 && m >= 5) || y > 31)
            s = "?", y -= 30;
        cout << s << ' ' << y << ' ' << m << ' ' << d << endl;
    }
}

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<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    while(1){
        string s;
        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 <iostream>
#include <string>
using namespace std;
using llong = long long;

int main() {
		string s;
		llong y, m, d;

		while (cin >> s, s == "HEISEI") {
				cin >> y >> m >> d;

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

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

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int a, b, c;
string str;

void solve() {
    cin >> a >> b >> c;
    if (a <= 30) {
        cout << str << " " << a << " " << b << " " << c << endl;
    } else if (a > 31) {
        cout << "? " << a-30 << " " << b << " " << c << endl;
    } else {
        if (b <= 4) {
            cout << str << " " << a << " " << b << " " << c << endl;
        } else {
            cout << "? " << a-30 << " " << b << " " << c << endl;
        }
    }
}

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
    cout.precision(20);
    cerr << fixed;
    cerr.precision(6);
#ifdef LOCAL
    //freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif  
    while (cin >> str) {
        if (str == "#") break;
        solve();
    }
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
#define Would
#define you


int main() {
	string h;
	while (1) {
		cin >> h;
		if (h == "#") { break; }
		int a, b, c;
		cin >> a >> b >> c;
		if (a > 31||(a==31&&b>=5)) {
			cout << "?" << " ";
			a -= 30;
		}
		else { cout << "HEISEI" << " "; }
		cout << a << " " << b << " " << c << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    string s; cin >> s;
    if (s == "#") break;
    int y, m, d; cin >> y >> m >> d;
    if (10000 * y + 100 * m + d <= 310430) {
      cout << "HEISEI " << y << ' ' << m << ' ' << d << '\n';
    } else {
      cout << "? " << y - 30 << ' ' << m << ' ' << d << '\n';
    }
  }
}