Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

//ConvReiwa ..
func ConvReiwa(sd []string) []string {
	var ne []string
	yr, _ := strconv.Atoi(sd[1])
	mn, _ := strconv.Atoi(sd[2])

	switch {
	case yr < 31:
		return sd
	case yr == 31 && mn < 5:
		return sd
	default:
		ne = append(ne, "?")
		ne = append(ne, strconv.Itoa(yr-30))
		ne = append(ne, sd[2])
		ne = append(ne, sd[3])
		return ne
	}
}

func main() {

	for sc.Scan() {

		str := sc.Text()

		if str == "#" {
			break
		}

		sdt := strings.Split(str, " ")
		ans := ConvReiwa(sdt)

		fmt.Printf("%s %s %s %s\n", ans[0], ans[1], ans[2], ans[3])
	}

}

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

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






string g;
int y, m, d;
//---------------------------------------------------------------------------------------------------
void _main() {
    while (cin >> g) {
        if (g == "#") return;
        cin >> y >> m >> d;

        if (31 < y) {
            g = "?";
            y -= 30;
        }
        else if (y == 31) {
            if (4 < m) {
                g = "?";
                y -= 30;
            }
        }

        printf("%s %d %d %d\n", g.c_str(), y, m, d);
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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


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



	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}



signed main()
{
	//IOS();
	vector<int>ans;
	while(1){
		string s;
		cin >> s;
		if(s == "#")break;
		int y,m,d;
		cin>>y>>m>>d;
		if(y>31||(y==31&&m>4)){
			printf("? %lld %lld %lld\n",y-30,m,d);
		}else{
			printf("HEISEI %lld %lld %lld\n",y,m,d);
		}
	}
}

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

bool solve() {
  string g;
  int y, m, d;
  cin >> g;
  if (g == "#") return (false);
  cin >> y >> m >> d;
  if (y >= 32 || y == 31 && m >= 5) {
    cout << "? " << y-30 << " " << m << " " << d << endl;
  } else {
    cout << "HEISEI " << y << " " << m << " " << d << endl;
  }
  return (true);
}

int main() {
  while (solve());
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1007;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	while(1){
		string s;
		cin>>s;
		if(s[0]=='#')break;
		ll a,b,c;
		cin>>a>>b>>c;
		if(a<31 || (a==31&&b<5)){
			cout<<s<<" "<<a<<" "<<b<<" "<<c<<endl;
		}else{
			s = "?";
			ll d = 0;
			d += c;
			ll y=31,m=5;
			while(y!=a || m!=b){
				d += days[m];
				m++;
				if(m==13){
					m=1;
					y++;
				}
			}
			a = 1;b = 4;c = 30;
			while(d){
				if(c+d>days[b]){
					d -= (days[b] - c+1);
					c = 1;
					b++;
					if(b==13){
						b=1;
						a++;
					}
				}else{
					c+=d;
					d=0;
				}
			}
			cout<<s<<" "<<a<<" "<<b<<" "<<c<<endl;
		}
	}
}