#include <bits/stdc++.h>
char S[105];
int T[105];
int N;
int X[8] = {3, 2, 2, 1, 2, 1, 1, 0};
int main() {
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%s", S);
    N = 0;
    for (int i = 0; S[i]; i++) {
      if ('a' <= S[i] && S[i] <= 'z') T[i] = 0;
      if ('A' <= S[i] && S[i] <= 'Z') T[i] = 1;
      if ('0' <= S[i] && S[i] <= '9') T[i] = 2;
      N++;
    }
    int ans = 987654321;
    int s, e;
    int t = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i - 1; j < N; j++) {
        t = 0;
        for (int k = 0; k < N; k++) {
          if (k >= i && k <= j) continue;
          t |= (1 << T[k]);
        }
        if (j - i + 1 >= X[t]) {
          if (ans > j - i + 1) {
            ans = j - i + 1;
            s = i;
            e = j;
          }
        }
      }
    }
    t = 0;
    for (int i = 0; i < N; i++) {
      if (s <= i && i <= e) continue;
      t |= (1 << T[i]);
    }
    for (int i = s; i <= e; i++) {
      if (!(t & 1)) {
        S[i] = 'a';
        t |= 1;
      } else if (!(t & 2)) {
        S[i] = 'A';
        t |= 2;
      } else {
        S[i] = '0';
        t |= 4;
      }
    }
    printf("%s\n", S);
  }
  return 0;
}
