Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

//ConvReiwa ..
func ConvReiwa(sd []string) []string {
	var ne []string
	yr, _ := strconv.Atoi(sd[1])
	mn, _ := strconv.Atoi(sd[2])

	switch {
	case yr < 31:
		return sd
	case yr == 31 && mn < 5:
		return sd
	default:
		ne = append(ne, "?")
		ne = append(ne, strconv.Itoa(yr-30))
		ne = append(ne, sd[2])
		ne = append(ne, sd[3])
		return ne
	}
}

func main() {

	for sc.Scan() {

		str := sc.Text()

		if str == "#" {
			break
		}

		sdt := strings.Split(str, " ")
		ans := ConvReiwa(sdt)

		fmt.Printf("%s %s %s %s\n", ans[0], ans[1], ans[2], ans[3])
	}

}

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