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>
using namespace std;
int main(void)
{
    string s;
    while(cin >> s, s != "#")
    {
        int a, b, c; cin >> a >> b >> c;
        if(a >= 32)
        {
            cout << "?" << " " << a  - 30 << " " << b << " " << c << endl;
        }
        else
        {
            if(a == 31 and b > 4)
            {
                cout << "?" << " " << a - 30 << " " << b << " " << c << endl;
            }
            else
            {
                cout << s << " " << a << " " << b << " " << c << endl;
            }
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	char buf[7];
	int year,month,day;

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		scanf("%d %d %d",&year,&month,&day);

		if((year < 31) || (year == 31 && month <= 3) ||
				(year == 31 && month == 4 && day <= 30)){

			printf("HEISEI %d %d %d\n",year,month,day);

		}else{

			printf("? %d %d %d\n",year+1-31,month,day);
		}
	}

	return 0;
}

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

using namespace std;

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


  while(1){
    scanf("%s", 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>
using namespace std;

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

   
 
   
    
    
	 
      
    
  
  

  
  

  return 0;
}

C++: #include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



int main(){
   string s;
   while(cin >> s){
       if(s == "#")return 0;
       int y,m,d;
       cin >> y  >> m >> d;
       tuple<int, int, int> t = make_tuple(y, m ,d), w = make_tuple(31, 4, 30);
       if(t > w){
           cout<<"?"<<" "<<y-30<<" "<<m<<" "<<d<<endl;
       }else{
           cout<<"HEISEI"<<" "<<y<<" "<<m<<" "<<d<<endl;
       }
   }
}

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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int main(void){

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

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) a = b;
  return a > b;
}
template<class T> inline bool chmax(T&a, T b) {
  if (a < b) a = b;
  return a < b;
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;

int main(){
    while(cin >> s && s != "#"){
        ll y,m,d;
        bool f = false;
        cin >> y >> m >> d;
        if(y == 31){
            if(m >= 5)f = true;
        }
        else if(y > 31)f = true;
        if(f)cout << "?";
        else cout << s;
        cout << " " << y - f*(30) << " " << m << " " << d << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int a,b,c;
	while(cin>>s,s!="#"){
		cin>>a>>b>>c;
		if(a>31||(a==31&&b>4))cout<<"?",a-=30;
		else cout<<s;
		cout<<' '<<a<<' '<<b<<' '<<c<<endl;
	}
}

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

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

C++: #include<stdio.h>

int main(){
  char g[101][10];
  int y[105],m[105],d[105];
  
  int i=0;
  for(;;){
    scanf("%s%d%d%d", g[i], &y[i], &m[i], &d[i]);
    if(g[i][0]=='#') break;
    i++;
  }

  int j;
  for(j=0;j<i;j++){
    
    if(((y[j]>=31)&&(m[j]>=5)||y[j]>=32)){
      printf("? %d %d %d\n",y[j] - 30, m[j], d[j]);
    } else {
      printf("HEISEI %d %d %d\n", y[j], m[j], d[j]);
    }
    
  }

  
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<random>
using namespace std;

int main()
{
	string s;
	int y, m, d;
	vector<string> ans;
	while (cin >> s)
	{
		if (s == "#") break;
		cin >> y >> m >> d;
		if (y > 31 || (y == 31 && m > 4))
		{
			s = "?";
			y = y - 31 + 1;
		}
		s += " ";
		s += to_string(y);
		s += " ";
		s += to_string(m);
		s += " ";
		s += to_string(d);
		ans.push_back(s);
	}
	for (const auto& a : ans)
	{
		cout << a << endl;
	}
	
	return 0;

}