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>
using namespace std;

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

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

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

#define fi first
#define se second
#define show(x) cerr << #x << "=" << "\n"
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  FILE *stream2;
  stream1 = freopen("in.txt", "r", stdin);
  stream2 = freopen("out.txt", "w", stdout);
  if (stream1 == NULL) return 0;
  if (stream2 == NULL) return 0;
#endif
  string s;
  while (cin >> s) {
    if (s == "#") break;
    int a, b, c; cin >> a >> b >> c;
    pair<pair<int,int> ,int> p = make_pair(make_pair(a, b), c);
    pair<pair<int,int> ,int> q = make_pair(make_pair(31, 4), 30);
    if (p > q) {
      cout << "? " << a - 30 << " " << b << " " << c << endl;
    } else {
      cout << "HEISEI " << a << " " << b << " " << c << endl;
    }
  }
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  fclose(stream1);
  fclose(stream2);
#endif
  return 0;
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
#define fcout cout<<fixed<<setprecision(10)
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
//template<typename T>void pp(T x){cout<<x<<endl;}

using namespace std;
template<typename T> void test(vector<T> v){for(int i=0;i<v.size();i++){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

int main(){
    string s;
    int y,m,d;
    while(cin>>s&&s!="#"){
        cin>>y>>m>>d;
        if(y>31||(y==31&&m>4)){
            s="?";
            y-=30;
        }
        printf("%s %d %d %d",s.c_str(),y,m,d);
        cout<<endl;
    }
    return 0;
}

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 <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    while(true){
        string S; cin >> S;
        if(S=="#") break;
        int a,b,c; cin >> a >> b >> c;
        if(a>31 || a==31 && b>=5){
            cout << "? " << a-30 << " " << b << " " << c << "\n";
        } else {
            cout << S << " " << a << " " << b << " " << c << "\n";
        }
    }
}

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

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

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

    return 0;
}

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

using namespace std;

int main(){

  int y, m, d;
  string g;

  while(1){

    cin >> g ;
    if(g == "#")
      break;

    cin >> y >> m >> d;

    if(g!="HEISEI" || y<1 || y>100 || m<1 || m>12 || d<1 || d>31)
      break;

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

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

bool check(vector<int> &vec) {
  if( vec[0] >= 32 ) return true;
  if( vec[0] == 31 && vec[1] >= 5 ) return true;
  return false;
}

int main() {
  string g;
  while(cin >> g, g != "#" ) {
    vector<int> vec(3);
    rep(i,3) cin >> vec[i];
    cout << ( check(vec) ? "?" : g ) << " "; 
    cout << ( check(vec) ? vec[0]-30 : vec[0] );
    rep(i,2) {
      cout << " ";
      cout << vec[i+1];
    } puts("");
  }
  return 0;
}