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<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;


int main() {

    string s;
    while(true){
        cin>>s;
        if(s[0]=='#'){break;}
        int y,m,d;
        cin>>y>>m>>d;
        bool hei=true;
        if(y>=32){
            hei=false;
        }else if(y==31){
            if(m>=5){
                hei=false;
            }
        }
        if(hei){
            cout<<"HEISEI"<<" "<<y<<" "<<m<<" "<<d<<endl;
        }else{
            cout<<'?'<<" "<<y-30<<" "<<m<<" "<<d<<endl;
        }
    }



    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)











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

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

typedef long long ll;

int main(){
    string s;
    int a,b,c;
    while(cin >> s && s!="#"){
        cin >> a >> b >> c;
        int x = 400*a+40*b+c;
        if(x>=400*31+40*5+1){
            s = "?";
            a-=30;
        }
        cout << s << " " << a << " " << b << " " << c << endl;
    }
    return 0;
}

C++: //http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1275
//ヨセフスの問題 ブログを書きましょう！！
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
int main(void)
{
    string s;
    int y, m, d;
    while (cin >> s >> y >> m >> d)
    {
        if (s == "#")
            break;

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

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

	return 0;
}

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 || (y == 31 && m > 4)) {
            cout << "? " << y-30;
        } else {
            cout << s << " " << y;
        }
        cout << " " << m << " " << d << endl;
    }
}

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

using namespace std;

string s;
int y, m, d;

int main(void)
{
	while(1){
		cin >> s;
		if(s == "#") break;
		cin >> y >> m >> d;
		
		if(make_pair(y, make_pair(m, d)) > make_pair(30, make_pair(4, 30))){
			s = "?", y -= 30;
		}
		cout << s << " " << y << " " << m << " " << d << endl;
	}
	return 0;
}

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;
        string ans;
        if(y <= 30) ans = "HEISEI";
        else if(y >= 32){
            ans = "?";
            y -= 30
        }
        else{
            if(m <= 4) ans = "HEISEI";
            else{
                ans = "?";
                y -= 30;
            }
        }

        cout << ans << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}

C++: #include <iostream>


using namespace std;

int main(){
    string geng[100];
    int nen[100],getu[100],day[100];
    int i = 0;
    cin >> geng[i];
    while(geng[i] != "#"){
        cin >> nen[i] >> getu[i] >> day[i];
        if(nen[i] >= 32){
            cout << '?' << ' ' << nen[i] - 30 << ' ' << getu[i] << ' ' << day[i] << endl;
        }else{
            if(nen[i] == 31 && getu[i] >= 5){
                cout << '?' << ' ' << nen[i] - 30 << ' ' << getu[i] << ' ' << day[i] << endl;
            }else{
                cout << "HEISEI" << ' ' << nen[i] << ' ' << getu[i] << ' ' << day[i] << endl;
            }
        }
        i++;
        cin >> geng[i];
    }
    return 0;
}