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 <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        string s; cin>>s;
        if(s == "#") return 0;
        int y, m, d; cin>>y>>m>>d;

        if(31 < y || (y == 31 && 4 < m)){
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        }
        else{
            cout << s << " " << y << " " << m << " " << d << endl;
        }
    }
}

C++: #include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <list>


constexpr int INF = 1050000000;
constexpr int MOD = 1000000007;
constexpr long long LONGINF = 1005000000000000000;
using namespace std;

using ll = long long;
/*    UnionFind


class UnionFind {
private:
	std::vector<int> parent;
	std::vector<int> height;
	std::vector<int> m_size;

public:
	UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	void init(int size_) {
		parent.resize(size_);
		height.resize(size_, 0);
		m_size.resize(size_, 1);
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	int find(int x) {
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		int t = size(x) + size(y);
		m_size[x] = m_size[y] = t;
		if (height[x] < height[y]) parent[x] = y;
		else parent[y] = x;
		if (height[x] == height[y]) ++height[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		if (parent[x] == x) return m_size[x];
		return size(parent[x] = find(parent[x]));
	}
};


*/

int main() {
	

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

		int a, b, c; cin >> a >> b >> c;

		bool x = false;

		if (a < 31) {
			x = true;
		}
		else {
			if (a == 31 && b < 5) {
				x = true;
			}
		}

		if (x) {
			cout << s << " " << a << " " << b << " " << c << endl;
		}
		else {
			cout <<"? "<< a - 30 << " " << b << " " << c << endl;
		}

	}

}

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

int main() {
  string g;
  int y, m, d;
  while (true) {
    cin >> g >> y >> m >> d;
    if (g == "#") break;

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

    cout << "\n";
  }

  return 0;
}

C++: // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    string g; int y, m, d;
    while(cin >> g, g != "#") {
        cin >> y >> m >> d;

        string f = "";
        if(y >= 31) {
            if(y > 31) f = "?";
            else {
                if(m >= 5) f = "?";
                else f = "HEISEI";
            }
        }
        else {
            f = "HEISEI";
        }

        if(f == "?") y -= 30;
        cout << f << " " << y << " " << m << " " << d << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<30)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
using namespace std;
using ll = long long;

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


void solve(){
    int y,m,d;
    cin>>y>>m>>d;
    vector<int> h={31,4,30};
    if(h<vector<int>{y,m,d}){
        cout<<"? "<<y-30<<" "<<m<<" "<<d<<endl;
    }
    else cout<<"HEISEI "<<y<<" "<<m<<" "<<d<<endl;
}
int main(){
    string s;
    while(cin>>s,s!="#")solve();
    return 0;
}