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

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int a, b, c;
string str;

void solve() {
    cin >> a >> b >> c;
    if (a <= 30) {
        cout << str << " " << a << " " << b << " " << c << endl;
    } else if (a > 31) {
        cout << "? " << a-30 << " " << b << " " << c << endl;
    } else {
        if (b <= 4) {
            cout << str << " " << a << " " << b << " " << c << endl;
        } else {
            cout << "? " << a-30 << " " << b << " " << c << endl;
        }
    }
}

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
    cout.precision(20);
    cerr << fixed;
    cerr.precision(6);
#ifdef LOCAL
    //freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif  
    while (cin >> str) {
        if (str == "#") break;
        solve();
    }
    //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
#define Would
#define you


int main() {
	string h;
	while (1) {
		cin >> h;
		if (h == "#") { break; }
		int a, b, c;
		cin >> a >> b >> c;
		if (a > 31||(a==31&&b>=5)) {
			cout << "?" << " ";
			a -= 30;
		}
		else { cout << "HEISEI" << " "; }
		cout << a << " " << b << " " << c << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  while (true) {
    string s; cin >> s;
    if (s == "#") break;
    int y, m, d; cin >> y >> m >> d;
    if (10000 * y + 100 * m + d <= 310430) {
      cout << "HEISEI " << y << ' ' << m << ' ' << d << '\n';
    } else {
      cout << "? " << y - 30 << ' ' << m << ' ' << d << '\n';
    }
  }
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    while (true) {
        string s; cin >> s;
        if (s=="#") break;
        int y, m, d; cin >> y >> m >> d;

        string ret;
        if (y>31 || (y==31&&m>=5)) {
            ret+="? ";
            y-=30;
        }
        else ret+="HEISEI ";

        cout << ret << y << " " << m << " " << d << endl;
    }
}

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

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

C++: // #include "bits/stdc++.h"

#include <iostream>
#include <vector>
// #include <map>
#include <string>
// #include <algorithm>
// #include <numeric>
// #include <limits>

using namespace std;

struct Wareki {
	string g;
	int y;
	int m;
	int d;

	explicit Wareki() {};
	explicit Wareki(string g, int y, int m, int d) : g(g), y(y), m(m), d(d) {};
	void print() {
		cout << g << " " << y << " " << m << " " << d << endl;
	}
	Wareki convert() {
		Wareki converted;
		converted.g = g;
		converted.y = y;
		converted.m = m;
		converted.d = d;
		if ((y == 31 and m >= 5) or y > 31) {
			converted.g = "?";
			converted.y = y - 30;
		}
		return converted;
	}
};

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

	while (1) {
		cin >> g >> y >> m >> d;
		if (g == "#") {
			break;
		}
		Wareki before(g, y, m, d);
		Wareki after = before.convert();
		after.print();
	}

	// std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}