Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	const S = "HEISEI"
	io := NewIo()
	defer io.Flush()
	for io.Next() == S {
		y, m, d := io.NextInt(), io.NextInt(), io.NextInt()
		if y > 31 || y == 31 && m > 4 {
			io.Println("?", y-30, m, d)
		} else {
			io.Println(S, y, m, d)
		}
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

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;

}

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

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

C++: #include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"
#include "functional"
#include "stack"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, L, R, H, W;



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

	string s;
	getline(cin, s);
	while (s != "#") {
		int v[3] = {};
		int index = 0;
		//cout << s << endl;
		for (int i = 7; i < s.size(); i++) {
			//cout << i <<" "<<index<< endl;
			if (s[i] == ' ') {
				index++;
			}
			else {
				v[index] *= 10;
				v[index] += s[i] - '0';
			}
		}
		string ret;
		if (v[0] <= 30 || (v[0] == 31 && v[1] <= 4)) {
			ret += "HEISEI " + to_string(v[0]) + " " + to_string(v[1]) + " " + to_string(v[2]);
		}
		else {
			ret += "? " + to_string((v[0] - 30)) + " " + to_string(v[1]) + " " + to_string(v[2]);
		}
		cout << ret << endl;
		getline(cin, s);
	}
}