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 <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
#define Would
#define you


int main() {
	string h;
	while (1) {
		cin >> h;
		if (h == "#") { break; }
		int a, b, c;
		cin >> a >> b >> c;
		if (a >= 31) {
			cout << "?" << endl;
			a -= 30;
		}
		else { cout << "HEISEI" << endl; }
		cout << a << " " << b << " " << c << endl;
	}
}

C++: #include<bits/stdc++.h>
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

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

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

using namespace std;

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

  cin >> g >> y >> m >> d;

  if(g == "#") return 0;
  
  if(y >= 32 || (y == 31 && m >= 5)){
    g = "?";
    y -= 30;
  }
  
  cout << g << " " << y << " " << m << " " << d << endl;
  return 1;
}

int main(){
  while(solve());
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const string space=" ";
int main(){
	while(1){
		string g;
		int y,m,d;
		cin>>g;
		if(g=="#")break;
		cin>>y>>m>>d;
		if(y>31||y==31&&m>4){
			g="?";
			y-=30;
		}
		cout<<g<<space<<y<<space<<m<<space<<d;
	}
	return 0;
}

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

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

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

string s;
int y,m,d;

int main(){
  int i,j;
  bool ch =0;
  while(1){
    cin >> s;
    if(s=="#")break;
    ch = 0;
    cin >> y >> m >> d;
    if(y>31)ch=1;
    else if(y==31&&m>4)ch=1;
    if(ch==1)cout << "? " <<y-30 <<" "<< m <<" " << d<<endl;
    else cout << s <<" " << y << " " << m << " " << d<<endl;
  }
  return 0;
}

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

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

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

using namespace std;

using lint = long long;
using ldouble = long double;

bool solve() {
    string S;
    cin >> S;
    if (S == "#") return false;

    int Y, M, D;
    cin >> Y >> M >> D;

    if (Y > 31 || (Y == 31 && M > 4)) {
        S = "?";
        Y -= 30;
    }

    cout << S << " " << Y << " " << M << " " << D << endl;
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}

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

using namespace std;
using ll = long long int;
#define long ll

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

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

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

using namespace std;

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


  while(1){
    cin >> 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>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    while(1){
        string s;
        cin >> s;
        if(s == "#") break;
        int y,m,d;
        cin >> y >> m >> d;
        if(y > 31){
            cout << "?" << " " << y- 30 << " " << m << " " << d << endl;
        }else if(y == 31){
            if(m >= 5){
                cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
            }else{
                cout << s << " " << y << " " << m << " " << d << endl;
            }
        }else{
            cout << s << " " << y << " " << m << " " << d << endl;
        }
    }
    return 0;
}

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

int main() {
		string s;
		llong y, m, d;

		while (cin >> s, s == "HEISEI") {
				cin >> y >> m >> d;

				if (y > 31 || (y >= 31 && m >= 5)) {
						printf("? %lld %lld %lld\n", y - 30, m, d);
				}
				else {
						printf("HEISEI %lld %lld %lld\n", y, m, d);
				}
		}
}