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>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s,s!="#"){
		int y,m,d;
		cin>>y>>m>>d;
		bool heisei=!(y>31||(y==31&&m>4));
		if(!heisei){
			y-=30;
		}
		puta((heisei?s:"?"),y,m,d);
	}
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    string s;
    int y,m,d;
    cin >> s;
    if(s=="#") return 0;
    cin >> y >> m >> d;
    if(y>31||(y==31&&m>=5)){
      cout << "?" SP y-30 SP m SP d << endl;
    }else{
      cout << "HEISEI" SP y SP m SP d << endl;
    }
  }
  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 > 5))
      cout << "? " << y-30 << ' ' << m << ' ' << d << endl;
    else
      cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(long long i = (a); i < (b); i++)
#define rep(i,b) for(long long i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
 
template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

int main(){
	string s;
	while(cin >> s, s[0] != '#'){
		int y, m, d;
		cin >> y >> m >> d;
		if((m >= 5 and y == 31) or y > 31){
			cout << "?" << ' ' << y - 31 + 1 << ' ' << m << ' ' << d << endl;
		}else{
			cout << "HEISEI" << ' ' << y << ' ' << m << ' ' << d << endl;
		}
	}
}

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

int main(void){
    // Your code here!
    while(true){
        string g;
        int y,m,d;
        cin>>g;
        if(g=="#")break;
        cin>>y>>m>>d;
        if(y*10000+m*100+d<=31*10000+4*100+30){
            cout<<"HEISEI"<<" "<<y<<" "<<m<<" "<<d<<endl;
        }
        else{
            cout<<"?"<<" "<<y-30<<" "<<m<<" "<<d<<endl;
        }
    }    
}

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

using namespace std;

class dataset{

	string g;
	int y, m, d;

public:
	dataset(){
		setAll("", 0, 0, 0);
	}

	void setAll(const string &gengou, const int year, const int month, const int day){
		g = gengou;
		y = year;
		m = month;
		d = day;
	}
	void setG(const string &gengou){ g = gengou; }
	void setY(const int &year){ y = year; }


	int getY() const { return y; }
	int getM() const { return m; }

	string getAsString() const{
		stringstream ss;
		ss << g << " " << y << " " << m << " " << d;
		return ss.str();
	}

};


int main()
{
	//input data
	vector<string> input_data;
	while(true){
		string line = "";
		getline(cin, line);
		if(line == "#"){ break; }
		input_data.push_back(line);
	}

	// edit input
	const size_t num_input = input_data.size();
	vector<dataset> input_dataset(num_input);

	for(size_t i = 0; i < num_input; i++){

		stringstream ss(input_data[i]);
	    string buf;
		vector<string> temp;
		while(getline(ss, buf, ' ')){
		    temp.push_back(buf);
	    }

		input_dataset[i].setAll(temp[0], stoi(temp[1]),stoi(temp[2]),stoi(temp[3]));
	}

	//process
	for(auto &v: input_dataset){
		const int y = v.getY();
		const int m = v.getM();
		if(y >= 32){ 
			v.setG("?"); 
			v.setY(y - 30);
		}
		else if(y >= 31 && m >= 5){ 
			v.setG("?"); 
			v.setY(y - 30);
		}
	}

	//output
	for(auto &v: input_dataset){
		cout << v.getAsString() << endl;
	}


	//end
    return 0;
}

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

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