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 <iostream>
#include <string>
using namespace std;

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

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

C++: #include<stdio.h>
int main()
{
	char g[7];
	int y,m,d;
	while(1){
		scanf("%s",g);
		if(g[0]=='#'){
			break;
		}
		scanf("%d %d %d",&y,&m,&d);
		if(y<31){
			printf("HEISEI %d %d %d\n",y,m,d);
		}else if(y==31){
			if(m<=4){
				printf("HEISEI %d %d %d\n",y,m,d);
			}else{
				printf("? %d %d %d\n",y-30,m,d);
			}
		}else{
			printf("? %d %d %d\n",y-30,m,d);
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const string space=" ";
int main(){
	while(1){
		string g;
		int y,m,d;
		cin>>g;
		if(g=="#")break;
		cin>>y>>m>>d;
		if(y>31||y==31&&m>4){
			g="?";
			y-=30;
		}
		cout<<g<<space<<y<<space<<m<<space<<d<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
	string s;
	while(true){
		cin>>s;
		if(s=="#")break;
		int y,m,d;
		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<bits/stdc++.h>
using namespace std;
int main(){
  string g;
  int y,m,d;
  while(1){
    cin>>g>>y>>m>>d;
    if(g == "#") break;
    if(y>31 || (y==31 && m>=5)){
      cout<<"? "<<y-31+1<<" "<<m<<" "<<d<<endl;
    }
    else cout<<g<<" "<<y<<" "<<m<<" "<<d<<endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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

C++: #include <iostream>
#include <string>
using namespace std;
int main(void)
{
    string s;
    while(cin >> s, s != "#")
    {
        int a, b, c; cin >> a >> b >> c;
        if(a >= 32)
        {
            cout << "?" << " " << a  - 30 << " " << b << " " << c << endl;
        }
        else
        {
            if(a == 31 and b > 4)
            {
                cout << "?" << " " << a - 30 << " " << b << " " << c << endl;
            }
            else
            {
                cout << s << " " << a << " " << b << " " << c << endl;
            }
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	char buf[7];
	int year,month,day;

	while(true){
		scanf("%s",buf);
		if(buf[0] == '#')break;

		scanf("%d %d %d",&year,&month,&day);

		if((year < 31) || (year == 31 && month <= 3) ||
				(year == 31 && month == 4 && day <= 30)){

			printf("HEISEI %d %d %d\n",year,month,day);

		}else{

			printf("? %d %d %d\n",year+1-31,month,day);
		}
	}

	return 0;
}

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

using namespace std;

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


  while(1){
    scanf("%s", g);

    if( g == "#" ) break;

    scanf("%d %d %d", &y, &m, &d);

    if(y >= 32){
      y -= 30;
      printf("? %d %d %d\n",  y, m, d);
    }
    else if(y == 31 && m >= 5){
      printf("? 1  %d %d\n",  m, d);
    }
    else
      printf("HEISEI %d %d %d\n", y, m, d);
  }
  return 0;
}

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

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

   
 
   
    
    
	 
      
    
  
  

  
  

  return 0;
}

C++: #include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



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