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;

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

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

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

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 || 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;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while (cin >> s && s != "#") {
		int64 y, m, d;
		cin >> y >> m >> d;
		if (y > 31 || (y == 31 && m >= 5)) {
			printf("? %d %d %d\n", y-30, m, d);
		} else {
			printf("HEISEI %d %d %d\n", y, m, d);
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		string s; cin >> s;
		if(s=="#")break;
		int y,m,d; cin >> y >> m >> d;
		if(y<=30){
			cout << s << " " << y << " " << m << " " << d << endl;
		}else if(y==31){
			if(m<=4){
				cout << s << " " << y << " " << m << " " << d << endl;
			}else{
				cout << "? " << y-30 << " " << m << " " << d << endl;
			}
		}else{
			cout << "? " << y-30 << " " << m << " " << d << endl;
		}
	}
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=1; i<=n; i++)
using namespace std;
int main(){
  int y,m,d;
  string s;
  while(1){
    cin >> s;
    if(s == "#") break;
    cin >> y >> m >> d;
    if(y>=31){
     if(y==31 && m<5){
     }
     else {
       s = "?";
       y -= 30;
     }
    }
    cout << s << " " << y << " " << m << " " << d << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    string g;
    int y,m,d;
    while (cin>>g>>y>>m>>d) {
        if (g=="#") {
            break;
        } else {
            if (y<31) {
                cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;
            } else if (y==31) {
                if (m>4) {
                    cout<<"?"<<" "<<1<<" "<<m<<" "<<d<<endl;
                } else {
                    cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;
                }
            } else {
                cout<<"?"<<" "<<y-30<<" "<<m<<" "<<d<<endl;
            }
        }
    }
}

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
  string s{};int y,m,d;
  cin>>s;
  if(s=="#")return 0;
  cin>>y>>m>>d;
  if(y>31){
	  cout<<'?'<<" ";
	  y-=30;
  }
  else if(y==31){
	  if(m>=5){
		  cout<<'?'<<" ";
		  y-=30;
	  }
	  else cout<<s<<" ";
  }
  else cout<<s<<" ";
  cout<<y<<" "<<m<<" "<<d<<endl;
}
}