#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int m = s.length();
    string a[8], str;
    int num = 0, l = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == ':' && s[i - 1] == ':') {
        break;
      }
      l = i;
      if (s[i] == ':') {
        a[num++] = str;
        str = "";
      } else {
        str += s[i];
      }
    }
    if (num == 7) {
      a[7] = str;
    }
    num = 7;
    for (int i = m - 1; i >= l; i--) {
      if (s[i] == ':' && s[i + 1] == ':') {
        break;
      }
      if (s[i] == ':') {
        reverse((str).begin(), (str).end());
        a[num--] = str;
        str = "";
      } else {
        str += s[i];
      }
    }
    for (int i = 0; i < 8; i++) {
      while (a[i].length() < 4) {
        a[i] = '0' + a[i];
      }
    }
    string ans;
    for (int i = 0; i < 8; i++) {
      ans += a[i];
      if (i + 1 < 8) {
        ans += ':';
      }
    }
    cout << ans << "\n";
  }
}
