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>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

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

C++: #include <iostream>

using namespace std;

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

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

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

using namespace std;
using ll=long long;
using vl=vector<ll>;


#define all(a) a.begin(),a.end()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<n;i++)
#define LINF ((ll)1ll<<60)

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

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main(){
	string s;
	while (cin >> s) {
		if (s == "#")break;
		int y, m, d; cin >> y >> m >> d;
		if (y < 31 || (y == 31 && m < 5)) {
			cout << s << " " << y << " " << m << " " << d << endl;
		}
		else {
			cout << "? " << y-30 << " " << m << " " << d << endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;

int main(){
  string s;
  PP t=PP(31,P(4,30));
  while(cin>>s,s!="#"){
	int a,b,c;
	cin>>a>>b>>c;
	if(PP(a,P(b,c))>t){
	  cout<<"? ";
	  a-=30;
	}else cout<<s<<" ";
	cout<<a<<" "<<b<<" "<<c<<endl;
  }
  return 0;
}

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

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

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

C++: #include<cstdio>
#include<cstring>
using namespace std;

char g[10]; int y, m, d;

int main(){
	for(;;){
		scanf("%s", g);
		if(strcmp(g, "#") == 0) break;
		scanf("%d %d %d", &y, &m, &d);
		if(y > 31 || (y == 31 && m > 4)){
			printf("? %d %d %d\n", y - 30, m, d);
		}else{
			printf("HEISEI %d %d %d\n", y, m, d);
		}
	}
	return 0;
}