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++: //https://onlinejudge.u-aizu.ac.jp/challenges/sources/JAG/Prelim/2881

#include <bits/stdc++.h>

using namespace std;

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

    int y, m, d;
    cin >> y >> m >> d;

    if (y >= 32 || (y == 31 && m >= 5)) {
        g = "?";
        y -= 30;
    }

    cout << g << " " << y << " " << m << " " << d << endl;
    return true;
}


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

}

/*
 *
 */

C++: #define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(10);
}

#define int ll
void solve() {
	while (true) {
		int b, c, d;;
		string s;
		cin >> s;
		if (s == "#") return;
		cin >> b >> c >> d;
		int kaigen = 0;
		if (b > 31) {
			kaigen = 1;
		}
		if (b == 31 && c >= 5) {
			kaigen = 1;
		}
		if (kaigen == 1) {
			b -= 30;
			cout << "?";
		}
		else {
			cout << "HEISEI";
		}
		cout << " " << b << " " << c << " " << d << endl;
	}
}
#undef int

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

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

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

C++: #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

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

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

using namespace std;

int main(void){

  string g;
  int y,m,d;

  while(cin >> g){

    if(g=="#")
      break;

    cin >> y >> m >> d;

    if(y > 31){
      y=y-30;
      g="?";
    }

    else if(y==31 && m > 4){
      y=1;
      g="?";
    }
    
    cout << g << " " << y << " " << m << " " << d << endl;
  }

  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>=5))   g = "?", y -= 30;
        cout << g << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int main(){
	
	string str;
	int y,m,d;
	while(cin >> str,str[0] != '#'){
		cin >> y >> m >> d;
		if(y >= 5){
			cout << '?';
		}
		else{
			cout << str;
		}
		
		cout << ' ' << y << ' ' << m << ' ' << d << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	string s; int y, m, d;
	while (cin >> s, s != "#") {
		cin >> y >> m >> d;
		d += m * 100;
		if (y > 31 ||(y == 31 && d > 500)) cout << "? " << y - 30;
		else cout << "HEISEI " << y;
		cout << ' ' << m << ' ' << d % 100 << endl;
	}
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

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

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

int main(){
	string a;
	while(cin>>a){
		if(a[0]=='#')break;
		int b,c,d;
		cin>>b>>c>>d;
		if(b<31)cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		else if(b==31 &&  c<5)cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		else{
		b-=30;
		a = "?";
		cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		}

	}
	return 0;
}