#include <bits/stdc++.h>
using namespace std;
int n;
char ip[100][50], ans[100][50];
string s;
inline int read() {
  int s = 1, x = 0;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') s = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  return s ? x : -x;
}
bool special(int &len) {
  for (int i = 0; i < len - 2; i++) {
    if (s[i] == ':' && s[i + 1] == ':' && s[i + 2] == ':') return true;
  }
  return false;
}
void solve() {
  for (int j = 0; j < 100; j++) {
    for (int k = 0; k < 50; k++) {
      ip[j][k] = 'x';
      ans[j][k] = 'x';
    }
  }
  cin >> s;
  int len = s.length(), flag = -1, p = 0, p_group = -1;
  if (special(len)) {
    cout << "INVALID\n";
    return;
  }
  for (int j = 0; j < len; j++) {
    if (j < len - 1 && s[j] == ':' && s[j + 1] == ':') {
      if (flag == -1)
        flag = p;
      else {
        cout << "INVALID\n";
        return;
      }
      p++;
      j++;
      p_group = -1;
    } else if (s[j] == ':') {
      p++;
      p_group = -1;
    } else
      ip[p][++p_group] = s[j];
  }
  if ((p < 7 && flag == -1) || p > 7) {
    cout << "INVALID\n";
    return;
  }
  for (int j = 0; j <= p; j++) {
    int tot = 0;
    for (int k = 0; k < 50; k++) {
      if (ip[j][k] == 'x')
        break;
      else if ((ip[j][k] >= '0' && ip[j][k] <= '9') ||
               (ip[j][k] >= 'a' && ip[j][k] <= 'f')) {
        tot++;
      } else {
        cout << "INVALID\n";
        return;
      }
    }
    if (tot > 4) {
      cout << "INVALID\n";
      return;
    } else {
      for (int k = 0; k < 4 - tot; k++) {
        ans[j][k] = '0';
      }
      for (int k = 4 - tot; k < 4; k++) {
        ans[j][k] = ip[j][k - 4 + tot];
      }
    }
  }
  for (int j = 0; j <= p; j++) {
    for (int k = 0; k < 4; k++) {
      if (ans[j][k] == 'x') {
        cout << "INVALID\n";
        return;
      }
      cout << ans[j][k];
    }
    if (j != p) cout << ':';
    if (j == flag) {
      for (int k = 1; k <= (7 - p); k++) {
        printf("0000");
        if (k + j != 7) putchar(':');
      }
    }
  }
  cout << endl;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    solve();
  }
  return 0;
}
