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 <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
auto constexpr infty<int> = 1'100'100'100;
template<>
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

int main() {
  // cout << fixed << setprecision(10);

  string G;
  while (cin >> G && G != "#"s) {
    int Y, M, D; cin >> Y >> M >> D;
    int yymmdd = 10000 * Y + 100 * M + D;
    if (yymmdd >= 310501) {
      G = "?";
      Y -= 30;
    }
    cout << G << " " << Y << " " << M << " " << D << endl;
  }
  return 0;
}

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