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 <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int main(){
    string s;
    int y,m,d;
    while(cin>>s&&s!="#"){
        cin>>y>>m>>d;
        if(y>31||(y==31&&m>4)){
            s="?";
            y-=30;
        }
        printf("%s %d %d %d",s.c_str(),y,m,d);
        cout<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    while(true){
        string S; cin >> S;
        if(S=="#") break;
        int a,b,c; cin >> a >> b >> c;
        if(a>31 || a==31 && b>=5){
            cout << "? " << a-30 << " " << b << " " << c << "\n";
        } else {
            cout << S << " " << a << " " << b << " " << c << "\n";
        }
    }
}

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

int main() {
    string g;
    while (cin >> g, g != "#") {
        int y, m, d;
        cin >> y >> m >> d;

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

    return 0;
}

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

using namespace std;

int main(){

  int y, m, d;
  string g;

  while(1){

    cin >> g ;
    if(g == "#")
      break;

    cin >> y >> m >> d;

    if(g!="HEISEI" || y<1 || y>100 || m<1 || m>12 || d<1 || d>31)
      break;

    if((y>31) || (y==31 && m>4)){
      y=y-30;
      g="?";
    }
    
    cout << g << " " << y << " " << m << " " << d <<endl;
  }
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

bool check(vector<int> &vec) {
  if( vec[0] >= 32 ) return true;
  if( vec[0] == 31 && vec[1] >= 5 ) return true;
  return false;
}

int main() {
  string g;
  while(cin >> g, g != "#" ) {
    vector<int> vec(3);
    rep(i,3) cin >> vec[i];
    cout << ( check(vec) ? "?" : g ) << " "; 
    cout << ( check(vec) ? vec[0]-30 : vec[0] );
    rep(i,2) {
      cout << " ";
      cout << vec[i+1];
    } puts("");
  }
  return 0;
}

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

using namespace std;

string s;
int y, m, d;

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

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

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

    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    string g;
    cin >> g;
    if (g == "#") return 0;
    
    int y, m, d;
    cin >> y >> m >> d;
    if (y >= 32 || (y == 31 && m >= 5)) {
      cout << "? " << y - 30 << " " << m << " " << d << '\n';
    }
    else {
      cout << g << " " << y << " " << m << " " << d << '\n';
    }
  }
}

C++: #include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

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

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

using namespace std;

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

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

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