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>
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define repb(i,n) for(int i = (int)n;i >= 0;i--)
#define reps(i,m,n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i,m,n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v,n) sort(v,v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
#define ll long long int
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1;} return 0;}
using namespace std;
int main(int argc, char const *argv[]) {
    string s;
    while (cin >> s, s[0] != '#')
    {
        int m, d, y;
        cin >> y >> m >> d;
        if(y>31){
            cout << "? " << y-30 << " " << m << " " << d << endl;
        }
        else if (y==31)
        {
            if(m>=5)    
                cout << "? " << y - 30 << " " << m << " " << d << endl;
            else
                cout << s << " " << y << " " << m << " " << d << endl;
        }
        else{
            cout <<s<< " " << y << " " << m << " " << d << endl;
        }
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

C++: /**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	string g;
    while(cin >> g) {
        if(g == "#") break;
        int y, m, d; cin >> y >> m >> d;
        if(y <= 30 || (y == 31 && m <= 4)) {
            cout << g << " " << y << " " << m << " " << d << endl;
        } else {
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        }
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

C++: #include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;

int main(void)
{
	int i,n,m,d;
	char s[7];
	while(1)	{
		scanf("%s",s);
		if(s[0]=='#')	break;
		scanf("%d %d %d",&n,&m,&d);
		if(n>=32 || (n==31 && m>=5))	{
			strcpy(s,"?");
			n=n-30;
		}
		printf("%s %d %d %d\n",s,n,m,d);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    string s; cin >> s;
    if(s == "#") break;
    int y, m, d; cin >> y >> m >> d;
    bool ch = false;
    if(y > 31) {
      ch = true;
    } else if(y == 31 && m >= 5) {
      ch = true;
    }
    if(ch) {
      cout << "?" << " " << y-30 << " " << m << " " << d << endl;
    } else {
      cout << s << " " << y << " " << m << " " << d << endl;
    }
  }
}

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

int main(){
    int y,m,d;
    string g;
    while(true){
        cin >> g;
        if(g[0] == '#'){
            break;
        }
        cin  >> y >> m >> d;

        if(y>31){
            g = "?";
            y -= 30;
        }
        else if(y==31){
            if(m > 4){
                g = "?";
                y = 1;
            }
            // y=4の時は必ず平成
        }

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