#include <bits/stdc++.h>
using namespace std;
int main() {
  char str1[50], str2[50];
  int n, c, k, cnt, flag;
  cin >> n;
  while (n--) {
    flag = cnt = 0;
    cin >> str1;
    k = strlen(str1);
    str1[k] = ':';
    str1[k + 1] = '\0';
    for (int i = 0; i <= k; ++i) {
      if (str1[i] != ':')
        flag = 1;
      else if (flag == 1) {
        cnt++;
        flag = 0;
      }
    }
    for (int i = 0; i <= 38; ++i) {
      if (i == 4 || i == 9 || i == 14 || i == 19 || i == 24 || i == 29 ||
          i == 34)
        str2[i] = ':';
      else
        str2[i] = '0';
    }
    c = 0;
    int j = 38;
    for (int i = k - 1; i >= 0; i--) {
      if (str1[i] != ':') {
        c++;
        str2[j--] = str1[i];
      }
      if (str1[i] == ':') {
        if (c == 4) j--;
        if (c == 3) j -= 2;
        if (c == 2) j -= 3;
        if (c == 1) j -= 4;
        c = 0;
      }
      if (str1[i] == ':' && str1[i - 1] == ':') {
        j -= (8 - cnt) * 5;
        i--;
      }
    }
    for (int i = 0; i <= 37; ++i) cout << str2[i];
    cout << str2[38] << endl;
  }
}
