#include <bits/stdc++.h>
using namespace std;
char s[1000];
char s1[1000];
inline void solve(char *s, int n) {
  int t, p;
  for (t = 0, p = 0; p < n; ++p) {
    if (s[p] == ':') {
      for (int j = 0; j < 4 - t; ++j) printf("0");
      for (int j = p - t; j <= p; ++j) printf("%c", s1[j]);
      t = 0;
    } else
      t++;
  }
  t = 0;
  for (int i = n - 1; s1[i] != ':' && i >= 0; --i) t++;
  for (int i = 0; i < 4 - t; ++i) printf("0");
  for (int i = n - t; i < n; ++i) printf("%c", s1[i]);
  puts("");
}
int main() {
  int T, n, m;
  scanf("%d", &T);
  while (T--) {
    scanf("%s", s);
    n = strlen(s);
    m = n;
    for (int i = 0; i < n; ++i) s1[i] = s[i];
    for (int i = 0; i < n - 1; ++i)
      if (s[i] == ':' && s[i + 1] == ':') {
        m = 0;
        if (i == 0) {
          s1[m++] = '0';
          s1[m++] = ':';
        } else {
          for (int j = 0; j <= i; ++j) s1[m++] = s[j];
        }
        int num = 0;
        for (int i = 0; i < n; ++i)
          if (s[i] == ':') num++;
        for (int j = 0; j < 8 - num; ++j) s1[m++] = '0', s1[m++] = ':';
        if (i + 1 == n - 1) {
          s1[m++] = '0';
        } else {
          for (int j = i + 2; j < n; ++j) s1[m++] = s[j];
        }
        break;
      }
    solve(s1, m);
  }
  return 0;
}
