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 F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  while(cin >> s && s!="#") {
    int y,m,d;
    cin >> y >> m >> d;
    if(y<31) cout << s << " ";
    else if(y==31) {
      if(m<=4) cout << s << " ";
      else {
        cout << "?" << " ";
        y-=31;
        y++;
      }
    } else {
      cout << "?" << " ";
      y-=31;
      y++;
    }
    pr(y,m,d);
  }
}

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

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

using i64 = int64_t;

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

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)


int main() {
    string gen;
    while (cin >> gen && gen != "#") {
        int a, b, c; cin >> a >> b >> c;
        //?
        if (a > 31 || (a == 31 && b >= 5)) {
            out("?" << " " << a - 30 << " " << b << " " << c);
        } else {
            out("HEISEI " << a << " " << b << " " << c);
        }
    }
}

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

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

int main(){
    vector<string> ans;
    while (1) {
        string nengo;
        cin >> nengo;
        if (nengo == "HEISEI") solve();
        else break;
    }
}

C++: #include <iostream>


using namespace std;

int main(){
    string geng[100];
    int nen[100],getu[100],day[100];
    int i = 0;
    cin >> geng[i];
    while(geng[i] != "#"){
        cin >> nen[i] >> getu[i] >> day[i];
        if(nen[i] >= 32){
            cout << '?' << ' ' << nen[i] - 30 << ' ' << getu[i] << ' ' << day[i] << endl;
        }else{
            if(nen[i] == 31 && getu[i] >= 5){
                cout << '?' << ' ' << nen[i] - 30 << ' ' << getu[i] << ' ' << day[i] << endl;
            }else{
                cout << "HEISEI" << ' ' << nen[i] << ' ' << getu[i] << ' ' << day[i] << endl;
            }
        }
        i++;
        cin >> geng[i];
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define loop for(;;)
using i64 = int64_t;

int main() {
    loop {
        std::string s;
        i64 y, m, d;
        std::cin >> s;
        if (s == "#") {
            break;
        }
        std::cin >> y >> m >> d;
        if (y * 1000000 + m * 1000 + d >= 31 * 1000000 + 5 * 1000 +1) {
            printf("? %ld %ld %ld\n", y-30, m, d);
        }
        else {
            printf("HEISEI %ld %ld %ld\n", y, m, d);
        }
    }
}

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

#define rep(i, s, n) for (Int i = s; i < (Int)(n); i++)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
double EPS = 1e-10;
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    while (true) {
        string s;
        Int a, b, c;
        cin >> s;
        if (s == "#") break;
        cin >> a >> b >> c;
        if (a > 31) {
            a -= 30;
            s = "?";
        } else if (a == 31) {
            if (b >= 5) {
                a -= 30;
                s = "?";
            }
        }
        cout << s << " " << a << " " << b << " " << c << endl;
    }
    return 0;
}

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

void print(int y,int m,int d){
  cout<<y<<" "<<m<<" "<<d<<endl;
}

signed solve(string s){
  int y,m,d;
  cin>>y>>m>>d;
  if(y<31){
    cout<<s<<" ";
    print(y,m,d);
    return 0;
  }
  if(y==31&&m<4){
    cout<<s<<" ";
    print(y,m,d);
    return 0;
  }
  if(y==31&&m==4&&d<=30){
    cout<<s<<" ";
    print(y,m,d);
    return 0;
  }
  cout<<"? ";
  print(y-30,m,d);
}

signed main(){
  while(1){
    string s;
    cin>>s;
    if(s=="#") break;
    solve(s);
  }
  return 0;
}