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

Python: reiwa="?"
while True:
    data=input().split()
    g=data[0]
    if g == "#":
        break
    else:
        y=int(data[1])
        m=int(data[2])
        d=int(data[3])
    
    #平成
    if y<31 or (y==31 and m<5):
        print(f"{g} {y} {m} {d}")
    #新元号
    else:
        y=y-30
        print(f"{reiwa} {y} {m} {d}")

Python: ls_g=[]
ls_y=[]
ls_m=[]
ls_d=[]
cnt = -1
while True:
    try:
        ls=input().split()
        ls_g.append(ls[0])
        ls_y.append(int(ls[1]))
        ls_m.append(int(ls[2]))
        ls_d.append(int(ls[3]))
        cnt += 1
    except:
        break;

for _ in range(cnt):
    if ls_y[_]>31:
        ls_g[_]="?"
        ls_y[_]-=30
    elif ls_y[_]==31 and ls_m[_]>=5:
        ls_g[_]="?"
        ls_y[_]-=30
for i in range(cnt):
    print(ls_g[i]+" "+str(ls_y[i])+" "+str(ls_m[i])+" "+str(ls_d[i]))

Python: datum = []
while True:
    datum.append(input().split())
    if datum[-1][0]=='#':
        break
datum=datum[:-1]
ans = []
for data in datum:
    if int(data[1]) >= 31 and int(data[2]) >= 5:
        ans.append(['?', str(int(data[1])-30), str(data[2]), str(data[3])])
    else:
        ans.append(data)
ans2 = []
for a in ans:
    ans2.append(' '.join(a))
print('\n'.join(ans2))

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

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

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

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

    while(1){
        cin>>g>>y>>m>>d;
        if(g=="#")break;

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

    return 0;
}

C++: #include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

int testcase_ends() {
  char buf[8];
  scanf("%s", buf);
  std::string s = buf;
  if (s == "#") return 1;

  std::vector<int> a(3), b{31, 5, 1};
  for (auto& ai: a) scanf("%d", &ai);

  if (a < b) {
    printf("HEISEI %d %d %d\n", a[0], a[1], a[2]);
  } else {
    printf("? %d %d %d\n", a[0]-30, a[1], a[2]);
  }
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}