#include <iostream>
using namespace std;
int main() {
freopen("change.in","r",stdin);
freopen("change.out","w",stdout);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
string t;
for (int i = 0;i < s.length();i++) {
if (s[i] == '0') {
t += "0000";
}
else if (s[i] == '1') {
t += "0001";
}
else if (s[i] == '2') {
t += "0010";
}
else if (s[i] == '3') {
t += "0011";
}
else if (s[i] == '4') {
t += "0100";
}
else if (s[i] == '5') {
t += "0101";
}
else if (s[i] == '6') {
t += "0110";
}
else if (s[i] == '7') {
t += "0111";
}
else if (s[i] == '8') {
t += "1000";
}
else if (s[i] == '9') {
t += "1001";
}
else if(s[i] == 'A') {
t += "1010";
}
else if (s[i] == 'B') {
t += "1011";
}
else if (s[i] == 'C') {
t += "1100";
}
else if (s[i] == 'D') {
t += "1101";
}
else if (s[i] == 'E') {
t += "1110";
}
else {
t += "1111";
}
}
if (s.length() % 3) {
if (s.length() % 3 == 1) {
t = "00" + t;
}
else {
t = "0" + t;
}
}
for (int i = s.length();i >= 0;i--) {
}
}
return 0;
}