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>

using namespace std;

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

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

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

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

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

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

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

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
using ll=long long;
const int M=1010;


int main(){
	string s[110];
	int y[110],m[110],d[110];

	for(int i=0;;i++){
		cin>>s[i];
		if(s[i][0]=='#')break;
		cin>>y[i]>>m[i]>>d[i];
	}

	for(int i=0;;i++){
		if(s[i][0]=='#')break;
		if(y[i]<31||(y[i]==31&&m[i]<5))
			cout<<"HEISEI "<<y[i]<<" "<<m[i]<<" "<<d[i]<<endl;
		else cout<<"? "<<y[i]-30<<" "<<m[i]<<" "<<d[i]<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)

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

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 <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 998244353;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

//入出力高速化(非同期化)
void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

string solve() {
    int y, m, d;
    cin >> y >> m >> d;
    string ret;
    if (y <= 31 && m < 5) {
        ret = "HEISEI ";
        ret += to_string(y);
        ret += " ";
        ret += to_string(m);
        ret += " ";
        ret += to_string(d);
    } else {
        ret += "?";
        ret += " ";
        ret += to_string(y-30);
        ret += " ";
        ret += to_string(m);
        ret += " ";
        ret += to_string(d);
    }
    return ret;
}

int main(){
    vector<string> ans;
    while (1) {
        string nengo;
        cin >> nengo;
        if (nengo == "HEISEI") ans.push_back(solve());
        else break;
    }
    for (auto &i: ans) {
        cout << i << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>

using namespace std;

int main(){
	char dm[7];
	int y,m,d;
	while(1){
		scanf("%s",dm);
		if(dm[0]=='#')
		break;
		scanf("%d %d %d",&y,&m,&d);
		if(y<=31){
			if(y==31&&m>=5)
			printf("? 1 %d %d\n",m,d);
			else
			printf("HEISEI %d %d %d\n",y,m,d);
		}
		else{
			printf("? %d %d %d\n",y-31+1,m,d);
		}
	}
}

C++: #include <iostream>
using namespace std;
int main(){
  string s;
  while(cin >> s, s != "#"){
    int y, m, d;
    cin >> y >> m >> d;
    if(y < 31) cout << s << " " << y << " " << m << " " << d << endl;
    else if(y > 31 || m > 4) cout << "? " << y-30 << " " << m << " " << d << endl;
    else cout << s << " " << y << " " << m << " " << d << endl;
  }
  return 0;
}

C++: //#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <climits>

using namespace std;
using ll=long long;

void solve(){
  while(true){
    string str;
    cin >> str;
    if(str=="#")return;
    int y,m,d;
    cin >> y >> m >> d;
    if(y<31||(y==31&&m<5))
      cout << "HEISEI " << y << " " << m << " " << d << endl;
    else
      cout << "? " << y-30 << " " << m << " " << d << endl;
    
    

  }
}

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