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 <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e8;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

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

    return 0;
}

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

C++: #include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <fstream>
#include <string>

using namespace std;

struct mondai {
	int suisen;
	int nanido;
	int number;
};
bool hyouka(mondai a, mondai b) {
	if (a.nanido == b.nanido) {
		return a.suisen >= b.suisen;
	}
	else {
		return a.nanido >= b.nanido;
	}
}


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

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

int main(){
  while(1){
    string g ;
    
    cin>>g;
    if(g=="#") break;
    int y,m,d;
    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 <iostream>
#include<string>
using namespace std;
int main() {
	string S;
	
	int y, m, d;
	for (int i = 0; i < 10000; i++) {
		cin >>S>> y >> m >> d;
		if (S == "#") {
			return 0;
		}
		if (y > 31) {
			cout<< "?"<< " " << y - 30 << " " << m << " " << d << endl;
		}
	 else if (y<31) {
			cout <<S<<" "<<y<<" "<<m<<" "<<d<< endl;
			
		}
		else if (y == 31 && m >=5) {

			
			cout << "?"<<" "<<y-30<<" "<<m<<" "<< d <<endl;
			
		}
		else if (y == 31 && m <= 4) {
			cout << S<<" "<<y<<" "<<m<<" "<<d << endl;
			
		}
		
		
	}
	
		return 0;
	}

C++: #include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    int y,m,d;
    cin >> S;
    while(S != "#"){
        cin >> y >> m >> d;
        if(y > 31 || y == 31 && m > 4){
            S = "?";
            y -= 30;
        }
        cout << S << " " << y << " " <<  m << " " <<  d << endl;
        cin >> S;
    }
}