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>
using namespace std;
int main(void){
  for(;;){
    string g;
    int y, m, d;
    cin >> g;
    if(g == "#"){ return 0; }
    cin >> y >> m >> d;
    if( y < 31 || (y == 31 && m <= 4) ){
      cout << "HEISEI " << y << " " << m << " " << d << endl;
    }else{
      cout << "? " << y - 30 << " " << m << " " << d << endl; 
    }
  }
}

C++: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
int main(){
    string g;
    string s = "?";
    int y,m,d;
    while(1){
        cin >> g;
        if(g=="#") return 0;

        cin >> y >> m >> d;

        if(y>=31){
            if(y==31&&m>=5){
                cout << s << " " << y-30 << " " << m << " " << d << endl;
            }else if(y>=32){
                cout << s << " " << y-30 << " " << m << " " << d << endl;
            }else{
                cout << g << " " << y << " " << m << " " << d << endl;
            }
        }else{
            cout << g << " " << y << " " << m << " " << d << endl;
        }
    }

}

C++: #include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for(long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for(long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                                                            \
    (upper_bound((V).begin(), (V).end(), X) -                                  \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                                                               \
    {                                                                          \
        cerr << #v << ':';                                                     \
        for(auto xv : v) cerr << xv << ' ';                                    \
        cerr << endl;                                                          \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T &a, const T &b) {
    if(a > b) a = b;
    return a > b;
}
template <typename T> inline bool chmax(T &a, const T &b) {
    if(a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

signed main() {
    string g;
    while(true) {
        cin >> g;
        if(g == "#") return 0;
        int y, m, d;
        cin >> y >> m >> d;
        if(make_tuple(31, 5, 1) <= make_tuple(y, m, d)) {
            cout << "? " << y - 30 << ' ' << m << ' ' << d << endl;
        } else {
            cout << "HEISEI " << y << ' ' << m << ' ' << d << endl;
        }
    }
}

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

using namespace std;

int main(){
  string g[100];
  int y[100], m[100], d[100];
  int cnt_in = 0;

  for(;;){
    cin >> g[cnt_in];
    if(g[cnt_in] == "#"){
      break;
    }

    cin >> y[cnt_in] >> m[cnt_in] >> d[cnt_in];
    cnt_in++;
  }

  for(int i = 0; i < cnt_in; i++){
    if((y[i] > 31) || (y[i] == 31) && (m[i] >= 5)){
      cout << "?" << " " << y[i] - 30 << " " << m[i] << " " << d[i] << endl;
    }
    else{
      cout << g[i] << " " << y[i] << " " << m[i] << " " << d[i] << endl;
    }
  }

  return 0;
}

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

int main(){
  string s;
  int g,m,d;
  bool flg;
  while(1){
    flg=false;
    cin>>s;
    if(s=="#") break;
    cin>>g>>m>>d;
    if(g>=32){
      flg=true;
    }
    if(g>=31&&m>=5){
      flg=true;
    }
    if(flg){
      s="?";
      g-=30;
    }
    cout<<s<<" "<<g<<" "<<m<<" "<<d<<endl;
  }
  return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string g;
	int y, m, d;
	while (cin >> g) {
		if (g == "#")break;
		cin >> y >> m >> d;
		if (y > 31) {
			g = "?";
			y -= 30;
		}
		else if (y == 31) {
			if (m > 4) {
				g = "?";
				y -= 30;
			}

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