Go: package main

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

func main() {
	const S = "HEISEI"
	io := NewIo()
	defer io.Flush()
	for io.Next() == S {
		y, m, d := io.NextInt(), io.NextInt(), io.NextInt()
		if y > 31 || y == 31 && m > 4 {
			io.Println("?", y-30, m, d)
		} else {
			io.Println(S, y, m, d)
		}
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

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

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main(){
  string x;
  int year, month, day;
  while(cin >> x) {
    if(x == "#") break;
    cin >> year >> month >> day;
    bool is_new = false;
    if(year > 31) {
      is_new = true;
    } else {
      if(year == 31 && month > 4) is_new = true;
    }
    if(is_new) cout << "?" << " " << year - 30 << " " << month << " " << day << endl;
    else cout << "HEISEI" << " " << year << " " << month << " " << day << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>

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

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<set>
#include<iomanip>
using namespace std;
using ll=long long int;

int main() {

	string s;

	while (cin >> s, s != "#") {
		int y, m, d;
		cin >> y >> m >> d;

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

		cout << s << " " << y << " " << m << " " << d << endl;



	}

	return 0;
}