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;
#define rep(i,n) for(long long int i=0;i<n;++i)
typedef long long int ll;

int main(){

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

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

void sonomama(string s,int y,int m,int d){
    cout << s << " " << y << " " << m << " " << d << endl;
}

void henkan(string s,int y,int m,int d){
    cout << "?" << " " << y-30 << " " << m << " " << d << endl;
}

int main(){
    string s;
    int y, m, d;
    while(cin>>s,s[0]!='#'){
        cin >> y >> m >> d;
        if(y>31){
            henkan(s, y, m, d);
        
        }else if(y==31&&m>=5){
            henkan(s, y, m, d);
        }else{
            sonomama(s, y, m, d);
            
        }

    }

    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <sstream>
#include <complex>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <limits>
#include <numeric>

using namespace std;
#define all(a) begin(a), end(a)

using ll = long long;
using ull = unsigned long long;
template <typename T>
using vec = vector<T>;
template <typename T>
using vec2 = vector<vec<T>>;

template <typename V, typename H>
void resize(vector<V> &vec, const H h)
{
    vec.resize(h);
}

template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &h, const T... t)
{
    vec.resize(h);
    for (auto &v : vec)
    {
        resize(v, t...);
    }
}

template <typename V, typename T>
void fill(V &x, const T &val)
{
    x = val;
}

template <typename V, typename T>
void fill(vector<V> &vec, const T &val)
{
    for(auto &v:vec)
    {
        fill(v, val);
    }
}

struct pre_
{
    pre_()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(6);
    }
} pre__;

int main(void)
{
    while(1){

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

C++: #include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        string g; cin >> g;
        if (g == "#") break;
        int y, m, d; cin >> y >> m >> d;
        if (y > 31 or
            y == 31 and m >= 5) {
            y -= 30;
            g = "?";
        }
        cout << g << " " << y << " " << m << " " << d << endl;
    }

    return 0;
}