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 int long long
using namespace std;

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

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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;

#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back

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

C++: #include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(cin>>s,s!="#"){
    ll y,m,d;
    cin>>y>>m>>d;
    if(y>31){
      cout<<"?"<<" "<<y-30<<" "<<m<<" "<<d<<endl;
    }else if(y==31){
      if(m>=5){
	cout<<"?"<<" "<<1<<" "<<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;

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

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

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

using namespace std;

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

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

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

    cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
  }
}

C++: #include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

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

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

int main() {
    string s;
    while (cin >> s, s != "#") {
        int y, m, d; cin >> y >> m >> d;

        bool new_era = false;
        if (y > 31 || (y == 31 && m > 4)) {
            cout << "? ";
        } else {
            cout << s << " ";
        }
        cout << y << " " << m << " " << d << endl;
    }
}

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

string g; int y, m, d;

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

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

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

C++: #include<bits/stdc++.h>
using namespace std;
#define BIG 1000000007
#define ll long long int

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