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 <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 998244353;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

//入出力高速化(非同期化)
void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

void solve() {
    int y, m, d;
    cin >> y >> m >> d;
    if (y <= 30 || (y == 31 &&  m < 5)) {
        cout << "HEISEI";
        cout << " ";
        cout << y;
        cout << " ";
        cout << m;
        cout << " ";
        cout << d;
        cout << endl;
    } else {
        cout << "?";
        cout << " ";
        cout << y-30;
        cout << " ";
        cout << m;
        cout << " ";
        cout << d;
        cout << endl;
    }
}

int main(){
    vector<string> ans;
    while (1) {
        string nengo;
        cin >> nengo;
        if (nengo == "HEISEI") solve();
        else break;
    }
}

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

C++: #include <bits/stdc++.h>
#define loop for(;;)
using i64 = int64_t;

int main() {
    loop {
        std::string s;
        i64 y, m, d;
        std::cin >> s;
        if (s == "#") {
            break;
        }
        std::cin >> y >> m >> d;
        if (y * 1000000 + m * 1000 + d >= 31 * 1000000 + 5 * 1000 +1) {
            printf("? %ld %ld %ld\n", y-30, m, d);
        }
        else {
            printf("HEISEI %ld %ld %ld\n", y, m, d);
        }
    }
}

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

#define rep(i, s, n) for (Int i = s; i < (Int)(n); i++)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
double EPS = 1e-10;
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    while (true) {
        string s;
        Int a, b, c;
        cin >> s;
        if (s == "#") break;
        cin >> a >> b >> c;
        if (a > 31) {
            a -= 30;
            s = "?";
        } else if (a == 31) {
            if (b >= 5) {
                a -= 30;
                s = "?";
            }
        }
        cout << s << " " << a << " " << b << " " << c << endl;
    }
    return 0;
}

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

void print(int y,int m,int d){
  cout<<y<<" "<<m<<" "<<d<<endl;
}

signed solve(string s){
  int y,m,d;
  cin>>y>>m>>d;
  if(y<31){
    cout<<s<<" ";
    print(y,m,d);
    return 0;
  }
  if(y==31&&m<4){
    cout<<s<<" ";
    print(y,m,d);
    return 0;
  }
  if(y==31&&m==4&&d<=30){
    cout<<s<<" ";
    print(y,m,d);
    return 0;
  }
  cout<<"? ";
  print(y-30,m,d);
}

signed main(){
  while(1){
    string s;
    cin>>s;
    if(s=="#") break;
    solve(s);
  }
  return 0;
}