#include <bits/stdc++.h>
using namespace std;
string str, ans[10];
int l;
int cnt(string s) {
  int res = 0;
  string tmp = "";
  for (int i = 0; i < s.size(); i++) {
    if ((s[i] >= '0' && s[i] <= '9') || (s[i] >= 'a' && s[i] <= 'f')) {
      tmp += s[i];
    } else if (tmp.size() != 0) {
      res++;
      tmp = "";
    }
  }
  if (tmp != "") res += 1;
  return res;
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    cin >> str;
    int k = cnt(str);
    string tmp = "";
    str += ":";
    l = 0;
    for (int i = 1; i <= 8; i++) ans[i] = "";
    for (int i = 0; i < str.size(); i++) {
      if ((str[i] >= '0' && str[i] <= '9') ||
          (str[i] >= 'a' && str[i] <= 'f')) {
        tmp += str[i];
      } else if (str[i] == ':') {
        if (tmp != "") {
          for (int j = 1; j <= 4 - tmp.size(); j++) {
            ans[l + 1] += "0";
          }
          ans[++l] += tmp;
          tmp = "";
        }
        if (str[i + 1] == ':') {
          for (int j = 1; j <= 8 - k; j++) {
            l++;
            ans[l] = "0000";
          }
          i++;
          continue;
        }
      }
    }
    cout << ans[1];
    for (int i = 2; i <= l; i++) {
      cout << ":" << ans[i];
    }
    cout << endl;
  }
  return 0;
}
