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 <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



string g;
int y, m, d;

signed main() {
    while (1) {
        cin >> g;
        if (g=="#") break;
        bool h = 0;
        cin >> y >> m >> d;
        if (y<=30) h = 1;
        else if (32<=y) h = 0;
        else {
            if (m<=3) h = 1;
            else if (5<=m) h = 0;
            else {
                if (d==30) h = 1;
                else h = 0;
            }
        }
        if (h) cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
        else cout << "? " << y-30 << ' ' << m << ' ' << d << endl;

    }
}

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

using namespace std;

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

    string str;
    while(cin >> str && str != "#"){
        int y, m, d;
        cin >> y >> m >> d;
        if(y < 31){
            cout << str << " " << y << " " << m << " " << d << "\n";
        } else if(y == 31){
            if(m <= 4){
                cout << str << " " << y << " " << m << " " << d << "\n";
            }else{
                cout << "? " << y - 30 << " " << m << " " << d << "\n";
            }
        } else{
            cout << "? " << y - 30 << " " << m << " " << d << "\n";
        }
    }
}

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

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

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll mod;



int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	while (kkt) {
		string s; cin >> s; if (s == "#") break;
		ll y, m, d; cin >> y >> m >> d;
		if (y > 31 or (y == 31 && m > 4)) {
			cout << "? " << y - 30 << " " << m << " " << d << "\n";
		}
		else {
			cout << s << " " << y << " " << m << " " << d << "\n";
		}
	}
	return 0;

}

C++: #include <iostream>
#include <string>
using namespace std;

int main()  {
  string g;
  int y, m, d;

  while (cin >> g, g != "#") {
    cin >> y >> m >> d;
    if (y > 30 || (y == 31 && m > 4))
      cout << "? " << y-30 << ' ' << m << ' ' << d << endl;
    else
      cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
  }
  return 0;
}

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

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

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

C++: //https://onlinejudge.u-aizu.ac.jp/challenges/sources/JAG/Prelim/2881

#include <bits/stdc++.h>

using namespace std;

bool solve() {
    string g;
    cin >> g;
    if (g == "#") return false;

    int y, m, d;
    cin >> y >> m >> d;

    if (y >= 32 || (y == 31 && m >= 5)) {
        g = "?";
        y -= 30;
    }

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


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

}

/*
 *
 */