Vasya came up with a password to register for EatForces — a string s. The password in EatForces should be a string, consisting of lowercase and uppercase Latin letters and digits.

But since EatForces takes care of the security of its users, user passwords must contain at least one digit, at least one uppercase Latin letter and at least one lowercase Latin letter. For example, the passwords "abaCABA12", "Z7q" and "3R24m" are valid, and the passwords "qwerty", "qwerty12345" and "Password" are not. 

A substring of string s is a string x = s_l s_{l + 1} ... s_{l + len - 1} (1 ≤ l ≤ |s|, 0 ≤ len ≤ |s| - l + 1). len is the length of the substring. Note that the empty string is also considered a substring of s, it has the length 0.

Vasya's password, however, may come too weak for the security settings of EatForces. He likes his password, so he wants to replace some its substring with another string of the same length in order to satisfy the above conditions. This operation should be performed exactly once, and the chosen string should have the minimal possible length.

Note that the length of s should not change after the replacement of the substring, and the string itself should contain only lowercase and uppercase Latin letters and digits.

Input

The first line contains a single integer T (1 ≤ T ≤ 100) — the number of testcases.

Each of the next T lines contains the initial password s~(3 ≤ |s| ≤ 100), consisting of lowercase and uppercase Latin letters and digits.

Only T = 1 is allowed for hacks.

Output

For each testcase print a renewed password, which corresponds to given conditions. 

The length of the replaced substring is calculated as following: write down all the changed positions. If there are none, then the length is 0. Otherwise the length is the difference between the first and the last changed position plus one. For example, the length of the changed substring between the passwords "abcdef" → "a7cdEf" is 4, because the changed positions are 2 and 5, thus (5 - 2) + 1 = 4.

It is guaranteed that such a password always exists.

If there are several suitable passwords — output any of them.

Example

Input

2
abcDCE
htQw27


Output

abcD4E
htQw27

Note

In the first example Vasya's password lacks a digit, he replaces substring "C" with "4" and gets password "abcD4E". That means, he changed the substring of length 1.

In the second example Vasya's password is ok from the beginning, and nothing has to be changed. That is the same as replacing the empty substring with another empty substring (length 0).

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation

Greedy algorithms


Solutions:
def check(s, L, R):
	for i in s:
		if i >= L and i <= R:
			return False
	return True

def ok(s):
	low = True
	for i in s:
		if i >= 'a' and i <= 'z':
			low = False
			break
	if low:
		return False
	low = True
	for i in s:
		if i >= 'A' and i <= 'Z':
			low = False
			break
	if low:
		return False
	low = True
	for i in s:
		if i >= '0' and i <= '9':
			low = False
			break
	if low:
		return False
	return True
t = int(input())
for tc in range(t):
	s = str(input())
	need = ''
	if check(s, 'a', 'z'):
		need += 'a'
	if check(s, 'A', 'Z'):
		need += 'A'
	if check(s, '0', '9'):
		need += '0'
	n = len(s)
	m = len(need)
	idx = 0
	ans = ''
	while idx + m <= n:
		st = 0
		ans = ''
		for i in range(n):
			if i >= idx and st < m:
				ans += need[st]
				st += 1
			else:
				ans += s[i]
		if ok(ans):
			break
		idx += 1
	print(ans)


def check_pass(x):
	(latin_big, latin_small, digit) = (0, 0, 0)
	for char in x:
		if char.isdigit():
			digit += 1
		elif char.isupper():
			latin_big += 1
		else:
			latin_small += 1
	return (latin_big, latin_small, digit)

def isdigit(x):
	return x[0].isdigit()

def issmall(x):
	return x[0].islower()

def isupper(x):
	return x[0].isupper()
t = int(input())
for test in range(t):
	st = input()
	n = len(st)
	(b, s, d) = check_pass(st)
	if b > 0 and s > 0 and (d > 0):
		print(st)
	elif b == n:
		print('1a' + st[2:])
	elif s == n:
		print('1A' + st[2:])
	elif d == n:
		print('aA' + st[2:])
	else:
		if b == 0:
			char = 'A'
			if s == 1:
				check_func = isdigit
			else:
				check_func = issmall
		elif s == 0:
			char = 'a'
			if b == 1:
				check_func = isdigit
			else:
				check_func = isupper
		else:
			char = '1'
			if s == 1:
				check_func = isupper
			else:
				check_func = issmall
		for i in range(n):
			if check_func(st[i]):
				print(st[:i] + char + st[i + 1:])
				break


a = 'abcdefghijklmnopqrstuvwxyz'
b = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
c = '0123456789'
for i in range(int(input())):
	s = input()
	s = list(s)
	(l, u, d) = (0, 0, 0)
	(il, iu, iid) = (0, 0, 0)
	for j in range(len(s)):
		if s[j] in a:
			il = j
			l += 1
		elif s[j] in b:
			iu = j
			u += 1
		else:
			d += 1
			iid = j
	if l == 0 and u == 0:
		s[1] = 'A'
		s[0] = 'a'
	elif l == 0 and d == 0:
		s[0] = 'a'
		s[1] = '1'
	elif d == 0 and u == 0:
		s[0] = 'A'
		s[1] = '1'
	elif u == 0:
		if d > l:
			s[iid] = 'A'
		else:
			s[il] = 'A'
	elif l == 0:
		if d > u:
			s[iid] = 'a'
		else:
			s[iu] = 'a'
	elif d == 0:
		if l > u:
			s[il] = '1'
		else:
			s[iu] = '1'
	print(''.join(s))


t = int(input())
for p in range(t):
	s = input()
	s = list(s)
	k = 0
	l = 0
	d = 0
	for i in s:
		if ord(i) > 96:
			k += 1
		elif ord(i) > 64:
			l += 1
		else:
			d += 1
	if k == 0:
		if l > 1:
			f = 0
			while not (ord(s[f]) > 64 and ord(s[f]) < 91):
				f += 1
			s[f] = 'a'
		elif d > 1:
			f = 0
			while not (ord(s[f]) > 47 and ord(s[f]) < 58):
				f += 1
			s[f] = 'a'
	if d == 0:
		if l > 1:
			f = 0
			while not (ord(s[f]) > 64 and ord(s[f]) < 91):
				f += 1
			s[f] = '1'
		elif k > 1:
			f = 0
			while not ord(s[f]) > 96:
				f += 1
			s[f] = '1'
	if l == 0:
		if d > 1:
			f = 0
			while not (ord(s[f]) > 47 and ord(s[f]) < 58):
				f += 1
			s[f] = 'A'
		elif k > 1:
			f = 0
			while not ord(s[f]) > 96:
				f += 1
			s[f] = 'A'
	print(''.join(s))


def check(s):
	res = []
	res.append(any((c.isdigit() for c in s)))
	res.append(any((c.islower() for c in s)))
	res.append(any((c.isupper() for c in s)))
	return res
for TT in range(1, int(input()) + 1):
	s = [*input()]
	ch = check(s)
	if all(ch):
		res = ''.join(s)
	elif ch.count(False) == 1:
		j = ch.index(False)
		for i in (0, 1):
			l = s[:]
			l[i] = '0aA'[j]
			if all(check(l)):
				res = ''.join(l)
				break
	else:
		if s[2].isdigit():
			pre = 'aA'
		elif s[2].islower():
			pre = '0A'
		elif s[2].isupper():
			pre = 'a0'
		res = pre + ''.join(s[2:])
	print(res)


import math
t = int(input())
for j in range(t):
	s = input()
	f1 = f2 = f3 = 0
	c1 = c2 = c3 = 0
	for i in range(len(s)):
		l = s[i]
		if l.isupper():
			f1 = 1
			c1 += 1
		elif l.islower():
			f2 = 1
			c2 += 1
		else:
			f3 = 1
			c3 += 1
	if f1 and f2 and f3:
		print(s)
	elif f1 and f2:
		for i in range(len(s)):
			l = s[i]
			if l.isupper() and c1 > 1 or (l.islower() and c2 > 1):
				print(s[:i] + '1' + s[i + 1:])
				break
	elif f1 and f3:
		for i in range(len(s)):
			l = s[i]
			if l.isupper() and c1 > 1 or (not l.isupper() and c3 > 1):
				print(s[:i] + 'a' + s[i + 1:])
				break
	elif f3 and f2:
		for i in range(len(s)):
			l = s[i]
			if c2 > 1 and l.islower() or (not l.islower() and c3 > 1):
				print(s[:i] + 'A' + s[i + 1:])
				break
	elif f1:
		print('a1' + s[2:])
	elif f2:
		print('A1' + s[2:])
	elif f3:
		print('aA' + s[2:])


op_map = {'d': lambda x: x.isdigit(), 'l': lambda x: x.islower(), 'u': lambda x: x.isupper()}
ch_map = {'d': '1', 'l': 'a', 'u': 'A'}
for _ in range(int(input())):
	p = input()
	d = {'u': 0, 'l': 0, 'd': 0}
	for c in p:
		if c.isdigit():
			d['d'] += 1
		elif c.isupper():
			d['u'] += 1
		else:
			d['l'] += 1
	if d['d'] == 0 or d['u'] == 0 or d['l'] == 0:
		arr = list(d.keys())
		arr.sort(reverse=True, key=lambda x: d[x])
		(op1, op2, op3) = arr
		p_n = ''
		added1 = False
		added2 = d[op2] > 0
		for c in p:
			if not added1:
				if op_map[op1](c):
					p_n += ch_map[op3]
					added1 = True
					continue
			elif not added2:
				if op_map[op1](c):
					p_n += ch_map[op2]
					added2 = True
					continue
			p_n += c
		print(p_n)
	else:
		print(p)


t = int(input())
change = ['a', 'A', '0']
for _ in range(t):
	s = [c for c in input()]
	l = [0, 0, 0]
	for i in range(len(s)):
		tp = 2
		if s[i] >= 'a' and s[i] <= 'z':
			tp = 0
		elif s[i] >= 'A' and s[i] <= 'Z':
			tp = 1
		l[tp] += 1
	for i in range(len(s)):
		tp = 2
		if s[i] >= 'a' and s[i] <= 'z':
			tp = 0
		elif s[i] >= 'A' and s[i] <= 'Z':
			tp = 1
		if l[tp] > 1:
			for j in range(3):
				if not l[j]:
					s[i] = change[j]
					l[tp] -= 1
					l[j] += 1
					break
	print(''.join(s))


t = int(input())
ints = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

def is_int(l):
	if l in ints:
		return True
	return False

def is_lower(l):
	if l.lower() == l:
		return True
	return False

def is_upper(l):
	if l.upper() == l:
		return True
	return False

def Print(s):
	p = ''
	for k in s:
		p += k
	print(p.strip())
CAP_LETT = 'A'
SMALL_LETT = 'a'
NUM_LETT = '1'
for i in range(t):
	s1 = str(input().strip())
	s = []
	for k in s1:
		s.append(k)
	cap = False
	small = False
	num = False
	cap_indices = []
	small_indices = []
	num_indices = []
	cap_and_small = False
	cap_and_num = False
	small_and_num = False
	cs_index = None
	cn_index = None
	sn_index = None
	for j in range(len(s)):
		lett = s[j]
		if is_int(lett):
			num = True
			num_indices.append(j)
		elif is_lower(lett):
			small = True
			small_indices.append(j)
		else:
			cap = True
			cap_indices.append(j)
		if num and small and (sn_index != None):
			sn_index = j
		if num and cap and (cn_index != None):
			cn_index = j
		if cap and small and (cs_index != None):
			cs_index = j
	if small and cap and num:
		Print(s)
	elif small and cap:
		if len(small_indices) > 1:
			s[small_indices[len(small_indices) - 1]] = NUM_LETT
		elif len(cap_indices) > 1:
			s[cap_indices[len(cap_indices) - 1]] = NUM_LETT
		Print(s)
	elif num and cap:
		if len(num_indices) > 1:
			s[num_indices[len(num_indices) - 1]] = SMALL_LETT
		elif len(cap_indices) > 1:
			s[cap_indices[len(cap_indices) - 1]] = SMALL_LETT
		Print(s)
	elif small and num:
		if len(small_indices) > 1:
			s[small_indices[len(small_indices) - 1]] = CAP_LETT
		elif len(num_indices) > 1:
			s[num_indices[len(num_indices) - 1]] = CAP_LETT
		Print(s)
	elif small:
		s[0] = CAP_LETT
		s[1] = NUM_LETT
		Print(s)
	elif num:
		s[0] = CAP_LETT
		s[1] = SMALL_LETT
		Print(s)
	elif cap:
		s[0] = SMALL_LETT
		s[1] = NUM_LETT
		Print(s)


digits = '0123456789'
lowers = 'abcdefghijklmnopqrstuvwxyz'
uppers = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def get_ans(s, oldset, newc):
	for c in s:
		if c in oldset:
			return s.replace(c, newc, 1)
t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	(dc, lc, uc) = (0, 0, 0)
	for c in s:
		if c in digits:
			dc += 1
		if c in lowers:
			lc += 1
		if c in uppers:
			uc += 1
	if dc == n:
		ans = 'Aa' + s[2:]
	elif lc == n:
		ans = '1A' + s[2:]
	elif uc == n:
		ans = '1a' + s[2:]
	elif dc == 0:
		if lc > 1:
			ans = get_ans(s, lowers, '1')
		else:
			ans = get_ans(s, uppers, '1')
	elif lc == 0:
		if dc > 1:
			ans = get_ans(s, digits, 'a')
		else:
			ans = get_ans(s, uppers, 'a')
	elif uc == 0:
		if lc > 1:
			ans = get_ans(s, lowers, 'A')
		else:
			ans = get_ans(s, digits, 'A')
	else:
		ans = s
	print(ans)


t = int(input())
lst = []
for i in range(t):
	s0 = input()
	s = list(s0)
	a = 0
	A = 0
	a0 = 0
	na1 = 0
	nA1 = 0
	na01 = 0
	na2 = 0
	nA2 = 0
	na02 = 0
	for k in range(len(s)):
		if ord(s[k]) >= 48 and ord(s[k]) <= 57:
			a0 += 1
			na01 = na02
			na02 = k
		if ord(s[k]) >= 65 and ord(s[k]) <= 90:
			A += 1
			nA1 = nA2
			nA2 = k
		if ord(s[k]) >= 97 and ord(s[k]) <= 122:
			a += 1
			na1 = na2
			na2 = k
	if a0 == 0 and a > 0 and (A > 1):
		s[nA2] = '0'
		a0 = 1
	elif a0 == 0 and a > 1 and (A > 0):
		s[na2] = '0'
		a0 = 1
	if a == 0 and a0 > 0 and (A > 1):
		s[nA2] = 'a'
		a = 1
	elif a == 0 and a0 > 1 and (A > 0):
		s[na02] = 'a'
		a = 1
	if A == 0 and a > 0 and (a0 > 1):
		s[na02] = 'A'
		A = 1
	elif A == 0 and a > 1 and (a0 > 0):
		s[na2] = 'A'
		A = 1
	if a0 == 0 and a == 0 and (A > 1):
		s[nA1] = '0'
		s[nA2] = 'a'
		a0 = 1
		a = 1
	if a0 > 0 and a == 0 and (A == 0):
		s[na01] = 'A'
		s[na02] = 'a'
		a = 1
		A = 1
	if a0 == 0 and a > 1 and (A == 0):
		s[na1] = '0'
		s[na2] = 'A'
		a0 = 1
		A = 1
	s0 = s[0]
	for j in range(1, len(s)):
		s0 += s[j]
	lst.append(s0)
for i in range(t):
	print(lst[i])


def main():
	for _ in range(int(input())):
		s = list(input())
		t = ''.join(('lU0'[c.isdigit() * 2 + c.isupper()] for c in s))
		(l, u, d) = sorted('lU0', key=t.count)
		if not t.count(u):
			s[:2] = {'l': 'U0', 'U': 'l0', '0': 'lU'}[d]
		elif not t.count(l):
			s[t.index(d)] = l
		print(''.join(s))
main()


import sys

def is_valid(s):
	lower = 'qwertyuioplkjhgfdsazxcvbnm'
	upper = 'QWERTYUIOPLKJHGFDSAZXCVBNM'
	digits = '1234567890'
	l = False
	u = False
	d = False
	for c in s:
		if c in upper:
			u = True
		elif c in lower:
			l = True
		else:
			d = True
	return l and u and d

def main():
	for case in range(int(input())):
		s = input()
		series = [c for c in s]
		ans = False
		if is_valid(series):
			print(s)
		else:
			for i in range(len(s)):
				temp = [c for c in series]
				temp[i] = 'a'
				if is_valid(temp):
					print(''.join(temp))
					ans = True
					break
				temp = [c for c in series]
				temp[i] = 'A'
				if is_valid(temp):
					print(''.join(temp))
					ans = True
					break
				temp = [c for c in series]
				temp[i] = '1'
				if is_valid(temp):
					print(''.join(temp))
					ans = True
					break
			if ans == False:
				if series[0] in 'qwertyuioplkjhgfdsazxcvbnm':
					print('A1', end='')
					print(s[2:])
				elif series[0] in 'QWERTYUIOPLKJHGFDSAZXCVBNM':
					print('a1', end='')
					print(s[2:])
				else:
					print('aA', end='')
					print(s[2:])
main()


t = int(input())
for i in range(t):
	s = input()
	c1 = 0
	c2 = 0
	c3 = 0
	for j in s:
		if j >= 'a' and j <= 'z':
			c1 = c1 + 1
			k1 = j
		elif j >= 'A' and j <= 'Z':
			c2 = c2 + 1
			k2 = j
		else:
			c3 = c3 + 1
			k3 = j
		if c1 >= 1 and c2 >= 1 and (c3 >= 1):
			break
	if c1 > 0:
		if c2 > 0:
			if c3 > 0:
				print(s)
				continue
			elif c1 != 1:
				s = s.replace(k1, '1', 1)
				print(s)
				continue
			else:
				s = s.replace(k2, '1', 1)
				print(s)
				continue
		elif c3 > 0:
			if c1 != 1:
				s = s.replace(k1, 'A', 1)
				print(s)
				continue
			else:
				s = s.replace(k3, 'A', 1)
				print(s)
				continue
		else:
			print('1' + 'A' + s[2:])
			continue
	elif c2 > 0:
		if c3 > 0:
			if c2 != 1:
				s = s.replace(k2, 'a', 1)
				print(s)
				continue
			else:
				s = s.replace(k3, 'a', 1)
				print(s)
				continue
		else:
			print('a' + '1' + s[2:])
			continue
	else:
		print('a' + 'A' + s[2:])
		continue


t = int(input())
for u in range(t):
	s = input()
	alph = 'abcdefghijklmnopqrstuvwxyz'
	ALPH = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	num = '1234567890'
	counts = [0, 0, 0]
	for char in s:
		if char in alph:
			counts[0] += 1
		elif char in num:
			counts[2] += 1
		else:
			counts[1] += 1
	if counts[0] > 0 and counts[1] > 0 and (counts[2] > 0):
		print(s)
	elif counts[0] == counts[1] == 0:
		print('aA' + s[2:])
	elif counts[0] == counts[2] == 0:
		print('a1' + s[2:])
	elif counts[1] == counts[2] == 0:
		print('A1' + s[2:])
	elif counts[0] == 0:
		if counts[1] > 1:
			for i in range(len(s)):
				if s[i] in ALPH:
					print(s[:i] + 'a' + s[i + 1:])
					break
		else:
			for i in range(len(s)):
				if s[i] in num:
					print(s[:i] + 'a' + s[i + 1:])
					break
	elif counts[1] == 0:
		if counts[0] > 1:
			for i in range(len(s)):
				if s[i] in alph:
					print(s[:i] + 'A' + s[i + 1:])
					break
		else:
			for i in range(len(s)):
				if s[i] in num:
					print(s[:i] + 'A' + s[i + 1:])
					break
	elif counts[0] > 1:
		for i in range(len(s)):
			if s[i] in alph:
				print(s[:i] + '1' + s[i + 1:])
				break
	else:
		for i in range(len(s)):
			if s[i] in ALPH:
				print(s[:i] + '1' + s[i + 1:])
				break


T = int(input())
PASS = [list(input()) for i in range(T)]

def string(t):
	s = ''
	for i in range(len(t)):
		s += t[i]
	return s
for t in PASS:
	tlist = [None for i in range(len(t))]
	for i in range(len(t)):
		if 48 <= ord(t[i]) <= 57:
			tlist[i] = 0
		elif 65 <= ord(t[i]) <= 90:
			tlist[i] = 1
		else:
			tlist[i] = 2
	if 0 in tlist and 1 in tlist and (2 in tlist):
		print(string(t))
	elif 0 in tlist and 1 in tlist:
		if tlist.count(0) != 1:
			x = tlist.index(0)
			t[x] = 'a'
			print(string(t))
		else:
			x = tlist.index(1)
			t[x] = 'a'
			print(string(t))
	elif 1 in tlist and 2 in tlist:
		if tlist.count(1) != 1:
			x = tlist.index(1)
			t[x] = '1'
			print(string(t))
		else:
			x = tlist.index(2)
			t[x] = '1'
			print(string(t))
	elif 2 in tlist and 0 in tlist:
		if tlist.count(2) != 1:
			x = tlist.index(2)
			t[x] = 'A'
			print(string(t))
		else:
			x = tlist.index(0)
			t[x] = 'A'
			print(string(t))
	elif 0 in tlist:
		t[0] = 'A'
		t[1] = 'a'
		print(string(t))
	elif 1 in tlist:
		t[0] = '1'
		t[1] = 'a'
		print(string(t))
	elif 2 in tlist:
		t[0] = 'A'
		t[1] = '1'
		print(string(t))


n = int(input())
while n:
	n -= 1
	s = input()
	u = l = d = 0
	length = len(s)
	for x in range(length):
		asc = ord(s[x])
		if asc >= 97 and asc <= 122:
			l += 1
		elif asc >= 65 and asc <= 90:
			u += 1
		elif asc >= 48 and asc <= 57:
			d += 1
	if l == 0 and u == 0 and (d != 0):
		print('a' + 'A' + s[2:])
	elif l != 0 and u == 0 and (d == 0):
		print('0' + 'A' + s[2:])
	elif l == 0 and u != 0 and (d == 0):
		print('a' + '0' + s[2:])
	elif l != 0 and u != 0 and (d == 0):
		if l == 1:
			if ord(s[0]) >= 97 and ord(s[0]) <= 122:
				print(s[0] + '0' + s[2:])
			else:
				print('0' + s[1:])
		elif u == 1:
			if ord(s[0]) >= 65 and ord(s[0]) <= 90:
				print(s[0] + '0' + s[2:])
			else:
				print('0' + s[1:])
		else:
			print('0' + s[1:])
	elif l != 0 and u == 0 and (d != 0):
		if l == 1:
			if ord(s[0]) >= 97 and ord(s[0]) <= 122:
				print(s[0] + 'A' + s[2:])
			else:
				print('A' + s[1:])
		elif d == 1:
			if ord(s[0]) >= 48 and ord(s[0]) <= 57:
				print(s[0] + 'A' + s[2:])
			else:
				print('A' + s[1:])
		else:
			print('A' + s[1:])
	elif l == 0 and u != 0 and (d != 0):
		if u == 1:
			if ord(s[0]) >= 65 and ord(s[0]) <= 90:
				print(s[0] + 'a' + s[2:])
			else:
				print('a' + s[1:])
		elif d == 1:
			if ord(s[0]) >= 48 and ord(s[0]) <= 57:
				print(s[0] + 'a' + s[2:])
			else:
				print('a' + s[1:])
		else:
			print('a' + s[1:])
	else:
		print(s)


t = int(input())
for _ in range(t):
	s = input()
	n = len(s)
	ndig = 0
	idig = -1
	nlow = 0
	ilow = -1
	nupp = 0
	iupp = -1
	for (i, c) in enumerate(s):
		if c.isnumeric():
			ndig += 1
			idig = i
		elif c.isupper():
			nupp += 1
			iupp = i
		else:
			nlow += 1
			ilow = i
	ans = list(s)
	if min(ndig, nlow, nupp):
		print(s)
		continue
	elif not max(ndig, nlow, nupp):
		print('Aa1' + s[3:])
		continue
	elif not ndig and (not nlow) and nupp:
		if iupp + 2 < n:
			ans[iupp + 1:iupp + 3] = ['1', 'a']
		else:
			ans[:2] = ['1', 'a']
	elif not ndig and nlow and (not nupp):
		if ilow + 2 < n:
			ans[ilow + 1:ilow + 3] = ['1', 'A']
		else:
			ans[:2] = ['1', 'A']
	elif not ndig and nlow and nupp:
		ans[next(iter(set(range(n)) - set([iupp, ilow])))] = '1'
	elif ndig and (not nlow) and (not nupp):
		if idig + 2 < n:
			ans[idig + 1:idig + 3] = ['A', 'a']
		else:
			ans[:2] = ['A', 'a']
	elif ndig and (not nlow) and nupp:
		ans[next(iter(set(range(n)) - set([iupp, idig])))] = 'a'
	else:
		ans[next(iter(set(range(n)) - set([idig, ilow])))] = 'A'
	print(''.join(ans))


n = int(input())

def valid(s):
	m = len(s)
	lower = []
	upper = []
	digit = []
	for i in range(m):
		if ord(s[i]) <= 57:
			digit.append(i)
		elif ord(s[i]) <= 90:
			upper.append(i)
		else:
			lower.append(i)
	d = len(digit)
	u = len(upper)
	l = len(lower)
	if d > 0 and u > 0 and (l > 0):
		return s
	if d == m:
		s[0] = 'A'
		s[1] = 'a'
		return s
	if u == m:
		s[0] = '1'
		s[1] = 'a'
		return s
	if l == m:
		s[0] = '1'
		s[1] = 'A'
		return s
	if d + u == m:
		if d > u:
			s[digit[0]] = 'a'
		else:
			s[upper[0]] = 'a'
		return s
	if d + l == m:
		if d > l:
			s[digit[0]] = 'A'
		else:
			s[lower[0]] = 'A'
		return s
	if u + l == m:
		if l > u:
			s[lower[0]] = '1'
		else:
			s[upper[0]] = '1'
		return s
for i in range(n):
	s = list(input())
	res = valid(s)
	print(''.join(res))


def Ted(s):
	(a, b, c) = (0, 0, 0)
	for i in range(len(s)):
		if 97 <= ord(s[i]) <= 122:
			a += 1
			x = i
		elif 65 <= ord(s[i]) <= 90:
			b += 1
			y = i
		elif 48 <= ord(s[i]) <= 57:
			c += 1
			z = i
	if a > 0 and b > 0 and (c > 0):
		return s
	if a > 0 and b == 0 and (c == 0):
		return 'A1' + s[2:]
	if a == 0 and b > 0 and (c == 0):
		return 'a1' + s[2:]
	if a == 0 and b == 0 and (c > 0):
		return 'Aa' + s[2:]
	if a > 0 and b > 0 and (c == 0):
		if a > 1:
			return s[:x] + '1' + s[x + 1:]
		if b > 1:
			return s[:y] + '1' + s[y + 1:]
	if a == 0 and b > 0 and (c > 0):
		if b > 1:
			return s[:y] + 'a' + s[y + 1:]
		if c > 1:
			return s[:z] + 'a' + s[z + 1:]
	if a > 0 and b == 0 and (c > 0):
		if c > 1:
			return s[:z] + 'A' + s[z + 1:]
		if a > 1:
			return s[:x] + 'A' + s[x + 1:]
t = int(input())
for i in range(t):
	print(Ted(str(input())))


def solve(s):
	tp = [''] * len(s)
	pat = {'a', 'A', '0'}
	for (i, ch) in enumerate(s):
		if ch.isupper():
			tp[i] = 'A'
		elif ch.islower():
			tp[i] = 'a'
		else:
			tp[i] = '0'
	st = set(tp)
	if len(st) == 3:
		return s
	elif len(st) == 1:
		return ''.join(pat - st) + s[2:]
	elif tp[0] == tp[1]:
		return ''.join(pat - st) + s[1:]
	else:
		return s[:-1] + ''.join(pat - st)
t = int(input())
for tt in range(t):
	s = input()
	print(solve(s))


a = 'abcdefghijklmnopqrstuvwxyz'
b = a.upper()
c = '1234567890'

def is_right(s):
	ok1 = ok2 = ok3 = 0
	for w in s:
		if w in a:
			ok1 = 1
		elif w in b:
			ok2 = 1
		elif w in c:
			ok3 = 1
		if ok1 == ok2 == ok3 == 1:
			return 1
	return 0
t = int(input())
for i in range(t):
	s = input()
	if is_right(s):
		print(s)
	else:
		sm = bg = ts = 0
		for w in s:
			if w in a:
				sm += 1
			elif w in b:
				bg += 1
			elif w in c:
				ts += 1
		if sm == 0 and bg == 0:
			print('aA' + s[2:])
		elif sm == 0 and ts == 0:
			print('a1' + s[2:])
		elif bg == 0 and ts == 0:
			print('A1' + s[2:])
		elif sm == 0:
			s = list(s)
			if bg > 1:
				for i in range(len(s)):
					if s[i] in b:
						s[i] = 'a'
						print(''.join(s))
						break
			else:
				for i in range(len(s)):
					if s[i] in c:
						s[i] = 'a'
						print(''.join(s))
						break
		elif bg == 0:
			s = list(s)
			if sm > 1:
				for i in range(len(s)):
					if s[i] in a:
						s[i] = s[i].upper()
						print(''.join(s))
						break
			else:
				for i in range(len(s)):
					if s[i] in c:
						s[i] = 'A'
						print(''.join(s))
						break
		else:
			s = list(s)
			if sm > 1:
				for i in range(len(s)):
					if s[i] in a:
						s[i] = '1'
						print(''.join(s))
						break
			else:
				for i in range(len(s)):
					if s[i] in b:
						s[i] = '1'
						print(''.join(s))
						break


t = int(input())
for q in range(0, t):
	a = input()
	lower = 0
	upper = 0
	digit = 0
	a = list(a)
	for i in range(0, len(a)):
		if a[i] >= 'a' and a[i] <= 'z':
			lower += 1
		elif a[i] >= 'A' and a[i] <= 'Z':
			upper += 1
		else:
			digit += 1
	if lower != 0:
		if digit == 0 or upper == 0:
			for i in range(0, len(a)):
				if digit == 0 and lower != 1 and (a[i] >= 'a') and (a[i] <= 'z'):
					a[i] = '4'
					digit = 1
				elif digit == 0 and lower == 1 and (a[i] >= 'A') and (a[i] <= 'Z'):
					a[i] = '4'
					digit = 1
				elif upper == 0 and lower != 1 and (a[i] >= 'a') and (a[i] <= 'z'):
					a[i] = 'A'
					upper = 1
				elif upper == 0 and lower == 1 and (a[i] >= '0') and (a[i] <= '9'):
					a[i] = 'A'
					upper = 1
	elif upper != 0:
		if digit == 0 or lower == 0:
			for i in range(0, len(a)):
				if digit == 0 and upper != 1 and (a[i] >= 'A') and (a[i] <= 'Z'):
					a[i] = '4'
					digit = 1
				elif digit == 0 and upper == 1 and (a[i] >= 'a') and (a[i] <= 'z'):
					a[i] = '4'
					digit = 1
				elif lower == 0 and upper != 1 and (a[i] >= 'A') and (a[i] <= 'Z'):
					a[i] = 'a'
					lower = 1
				elif lower == 0 and upper == 1 and (a[i] >= '0') and (a[i] <= '9'):
					a[i] = 'a'
					lower = 1
	if digit != 0:
		if lower == 0 or upper == 0:
			for i in range(0, len(a)):
				if lower == 0 and digit != 1 and (a[i] >= '0') and (a[i] <= '9'):
					a[i] = 'a'
					lower = 1
				elif lower == 0 and digit == 1 and (a[i] >= 'A') and (a[i] <= 'Z'):
					a[i] = 'a'
					lower = 1
				elif upper == 0 and digit != 1 and (a[i] >= '0') and (a[i] <= '9'):
					a[i] = 'A'
					upper = 1
				elif upper == 0 and digit == 1 and (a[i] >= 'a') and (a[i] <= 'z'):
					a[i] = 'A'
					upper = 1
	print(*a, sep='')


def hardened(string):
	hasDigit = hasLower = hasUpper = False
	for c in string:
		if c.isdigit():
			hasDigit = True
		if c.islower():
			hasLower = True
		if c.isupper():
			hasUpper = True
	patch = ''
	if not hasDigit:
		patch += '0'
	if not hasLower:
		patch += 'b'
	if not hasUpper:
		patch += 'B'
	if len(patch) == 0:
		return string
	if len(patch) == 2:
		return patch + string[2:]
	if len(patch) == 1:
		foundDigit = foundLower = foundUpper = False
		for i in range(len(string)):
			if string[i].isupper():
				if foundUpper:
					return string[:i] + patch + string[i + 1:]
				else:
					foundUpper = True
			elif string[i].islower():
				if foundLower:
					return string[:i] + patch + string[i + 1:]
				else:
					foundLower = True
			elif string[i].isdigit():
				if foundDigit:
					return string[:i] + patch + string[i + 1:]
				else:
					foundDigit = True
n = int(input())
for i in range(n):
	print(hardened(input()))


import math
t = int(input())
low = up = dig = False
cntlow = cntup = cntdig = 0

def isTwo():
	if low == up and low == True:
		return 1
	elif low == dig and dig == True:
		return 2
	elif dig == up and up == True:
		return 3
	return 0
while t > 0:
	t -= 1
	s = str(input())
	low = up = dig = False
	cntlow = cntup = cntdig = 0
	for c in s:
		if c.islower():
			low = True
			cntlow += 1
		elif c.isupper():
			up = True
			cntup += 1
		elif c.isdigit():
			cntdig += 1
			dig = True
	if low == True and up == True and (dig == True):
		print(s)
		continue
	if isTwo() == 1:
		if cntup >= cntlow:
			flag = True
			tmp = ''
			for c in s:
				if c.isupper() and flag == True:
					tmp += '1'
					flag = False
				else:
					tmp += c
			print(tmp)
		else:
			flag = True
			tmp = ''
			for c in s:
				if c.islower() and flag == True:
					tmp += '1'
					flag = False
				else:
					tmp += c
			print(tmp)
	elif isTwo() == 2:
		if cntdig >= cntlow:
			flag = True
			tmp = ''
			for c in s:
				if c.isdigit() and flag == True:
					tmp += 'A'
					flag = False
				else:
					tmp += c
			print(tmp)
		else:
			flag = True
			tmp = ''
			for c in s:
				if c.islower() and flag == True:
					tmp += 'A'
					flag = False
				else:
					tmp += c
			print(tmp)
	elif isTwo() == 3:
		if cntup >= cntdig:
			flag = True
			tmp = ''
			for c in s:
				if c.isupper() and flag == True:
					tmp += 'a'
					flag = False
				else:
					tmp += c
			print(tmp)
		else:
			flag = True
			tmp = ''
			for c in s:
				if c.isdigit() and flag == True:
					tmp += 'a'
					flag = False
				else:
					tmp += c
			print(tmp)
	elif isTwo() == 0:
		if s.islower():
			tmp = '1A'
			for i in range(2, len(s), 1):
				tmp += s[i]
			print(tmp)
		elif s.isupper():
			tmp = '1a'
			for i in range(2, len(s), 1):
				tmp += s[i]
			print(tmp)
		elif s.isdigit():
			tmp = 'aA'
			for i in range(2, len(s), 1):
				tmp += s[i]
			print(tmp)


lower = 'abcdefghijklmnopqrstuvwxyz'
upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'

def process_s(s):
	s_dict = {}
	s_dict['lower'] = []
	s_dict['upper'] = []
	s_dict['digits'] = []
	for i in range(len(s)):
		if s[i] in lower:
			s_dict['lower'].append(i)
		elif s[i] in upper:
			s_dict['upper'].append(i)
		else:
			s_dict['digits'].append(i)
	return s_dict
t = int(input())
while t:
	t -= 1
	s = list(input())
	s_dict = process_s(s)
	flag = True
	missing1 = ''
	missing2 = ''
	duplicate = ''
	for i in s_dict.keys():
		if len(s_dict[i]) == 0:
			if missing1 == '':
				missing1 = i
			else:
				missing2 = i
			flag = False
		elif len(s_dict[i]) > 1:
			duplicate = i
	if flag:
		print(''.join(s))
	else:
		if missing1 != '':
			s[s_dict[duplicate][0]] = eval(missing1)[0]
		if missing2 != '':
			s[s_dict[duplicate][1]] = eval(missing2)[0]
		print(''.join(s))


def check_input(s):
	count_a = 0
	count_A = 0
	count_1 = 0
	for i in s:
		if 97 <= ord(i) <= 122:
			count_a += 1
		elif 65 <= ord(i) <= 90:
			count_A += 1
		else:
			count_1 += 1
	if not count_a:
		if count_A == max(count_A, count_1):
			for i in range(len(s)):
				if 65 <= ord(s[i]) <= 90:
					s = s[:i] + 'a' + s[i + 1:]
					count_a += 1
					count_A -= 1
					break
		else:
			for i in range(len(s)):
				if 48 <= ord(s[i]) <= 57:
					s = s[:i] + 'a' + s[i + 1:]
					count_a += 1
					count_1 -= 1
					break
	if not count_A:
		if count_a == max(count_a, count_1):
			for i in range(len(s)):
				if 97 <= ord(s[i]) <= 122:
					s = s[:i] + 'A' + s[i + 1:]
					count_A += 1
					count_a -= 1
					break
		else:
			for i in range(len(s)):
				if 48 <= ord(s[i]) <= 57:
					s = s[:i] + 'A' + s[i + 1:]
					count_A += 1
					count_1 -= 1
					break
	if not count_1:
		if count_A == max(count_A, count_a):
			for i in range(len(s)):
				if 65 <= ord(s[i]) <= 90:
					s = s[:i] + '1' + s[i + 1:]
					count_1 += 1
					count_A -= 1
					break
		else:
			for i in range(len(s)):
				if 97 <= ord(s[i]) <= 122:
					s = s[:i] + '1' + s[i + 1:]
					count_1 += 1
					count_a -= 1
					break
	print(s)
n = int(input())
for i in range(n):
	check_input(input())


n = int(input())
r = []

def set_char(text, index, char):
	return f'{text[:index]}{char}{text[index + 1:]}'

def fix_password(t):
	small_letters = []
	capital_letters = []
	numbers = []
	for (i, c) in enumerate(t):
		if 48 <= ord(c) <= 57:
			numbers.append(i)
		if 65 <= ord(c) <= 90:
			capital_letters.append(i)
		if 97 <= ord(c) <= 122:
			small_letters.append(i)
	if len(numbers) == 0 and len(capital_letters) == 0:
		t = set_char(t, small_letters[0], '0')
		t = set_char(t, small_letters[1], 'A')
	elif len(capital_letters) == 0 and len(small_letters) == 0:
		t = set_char(t, numbers[0], 'a')
		t = set_char(t, numbers[1], 'A')
	elif len(numbers) == 0 and len(small_letters) == 0:
		t = set_char(t, capital_letters[0], '0')
		t = set_char(t, capital_letters[1], 'a')
	elif len(numbers) == 0:
		if len(small_letters) > 1:
			t = set_char(t, small_letters[0], '0')
		else:
			t = set_char(t, capital_letters[0], '0')
	elif len(small_letters) == 0:
		if len(numbers) > 1:
			t = set_char(t, numbers[0], 'a')
		else:
			t = set_char(t, capital_letters[0], 'a')
	elif len(capital_letters) == 0:
		if len(numbers) > 1:
			t = set_char(t, numbers[0], 'A')
		else:
			t = set_char(t, small_letters[0], 'A')
	return t
for i in range(n):
	t = input()
	rr = fix_password(t)
	r.append(rr)
for _r in r:
	print(_r)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def main():
	for _ in range(ii()):
		s = list(si())
		n = len(s)
		x = 0
		y = 0
		d = 0
		p1 = []
		p2 = []
		p3 = []
		num = '1234567890'
		for i in range(n):
			if s[i] in num and d == 0:
				d = 1
			elif s[i] in abc and x == 0:
				x = 1
			elif s[i] not in abc and s[i] not in num and (y == 0):
				y = 1
			if s[i] in num and d == 1:
				p1.append(i)
			elif s[i] in abc and x == 1:
				p2.append(i)
			elif s[i] not in abc and s[i] not in num and (y == 1):
				p3.append(i)
		if d == 0:
			if len(p2) >= 2:
				s[p2[1]] = '2'
				del p2[1]
			else:
				s[p3[1]] = '2'
				del p3[1]
		if x == 0:
			if len(p1) >= 2:
				s[p1[1]] = 'x'
				del p1[1]
			else:
				s[p3[1]] = 'x'
				del p3[1]
		if y == 0:
			if len(p2) >= 2:
				s[p2[1]] = 'Y'
				del p2[1]
			else:
				s[p1[1]] = 'Y'
				del p1[1]
		for i in s:
			print(i, end='')
		print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for t in range(int(input())):
	s = list(input())
	cu = cl = cd = 0
	lu = []
	ll = []
	ld = []
	for i in range(len(s)):
		if s[i] >= 'A' and s[i] <= 'Z':
			cu += 1
			lu.append(i)
		elif s[i] >= 'a' and s[i] <= 'z':
			cl += 1
			ll.append(i)
		elif s[i] >= '0' and s[i] <= '9':
			cd += 1
			ld.append(i)
	if cu == 0:
		if cl >= cd:
			s[ll[0]] = 'S'
			lu.append(ll[0])
			ll.remove(ll[0])
			cu += 1
		else:
			s[ld[0]] = 'N'
			lu.append(ld[0])
			ld.remove(ld[0])
			cu += 1
	if cl == 0:
		if cu >= cd:
			s[lu[0]] = 's'
			ll.append(lu[0])
			lu.remove(lu[0])
			cl += 1
		else:
			s[ld[0]] = 'n'
			ll.append(ld[0])
			ld.remove(ld[0])
			cl += 1
	if cd == 0:
		if cu >= cl:
			s[lu[0]] = '6'
			ld.append(lu[0])
			lu.remove(lu[0])
			cd += 1
		else:
			s[ll[0]] = '9'
			ld.append(ll[0])
			ll.remove(ll[0])
			cd += 1
	print(''.join(s))


def check(s):
	temp = []
	valid = {'A', 'a', '8'}
	for i in range(len(s)):
		if s[i].isupper():
			temp.append('A')
		elif s[i].islower():
			temp.append('a')
		else:
			temp.append('8')
	st = set(temp)
	if len(st) == 3:
		return s
	elif len(st) == 1:
		return ''.join(valid - st) + s[2:]
	elif temp[0] == temp[1]:
		return ''.join(valid - st) + s[1:]
	else:
		return s[:-1] + ''.join(valid - st)
for tt in range(int(input())):
	s = input()
	x = check(s)
	print(x)


num = int(input())
p = 1
while p <= num:
	a = input()
	lenth = len(a)
	b = 0
	x = 0
	y = 0
	z = 0
	o = 0
	_list = list(a)
	while b < lenth:
		if a[b] <= 'z' and a[b] >= 'a':
			x += 1
		elif a[b] <= 'Z' and a[b] >= 'A':
			y += 1
		else:
			z += 1
		b += 1
	if x == 0 and y > 1:
		while o == o:
			if _list[o] <= 'Z' and _list[o] >= 'A':
				_list[o] = 'a'
				x = 1
				break
			o += 1
		o = 0
	if z == 0 and y > 1:
		while o == o:
			if _list[o] <= 'Z' and _list[o] >= 'A':
				_list[o] = '1'
				z = 1
				break
			o += 1
		o = 0
	if x == 0 and z > 1:
		while o == o:
			if _list[o] >= '0' and _list[o] <= '9':
				_list[o] = 'a'
				x = 1
				break
			o += 1
		o = 0
	if y == 0 and z > 1:
		while o == o:
			if _list[o] >= '0' and _list[o] <= '9':
				_list[o] = 'A'
				y = 1
				break
			o += 1
		o = 0
	if z == 0 and x > 1:
		while o == o:
			if _list[o] <= 'z' and _list[o] >= 'a':
				_list[o] = '1'
				z = 1
				break
			o += 1
		o = 0
	if y == 0 and x > 1:
		while o == o:
			if _list[o] <= 'z' and _list[o] >= 'a':
				_list[o] = 'A'
				y = 1
				break
			o += 1
		o = 0
	for i in _list:
		print(i, end='')
	print('')
	b = 0
	x = 0
	y = 0
	z = 0
	o = 0
	lenth = 0
	a = 0
	p += 1


n = int(input())
alph = 'abcdefghijklmnopqrstuvwxyz'
digit = '0123456789'
for i in range(n):
	st = input()
	key = True
	a = 0
	b = 0
	c = 0
	for k in st:
		if k not in alph:
			key = False
		else:
			a = a + 1
		if k not in alph.upper():
			key = False
		else:
			b = b + 1
		if k not in digit:
			key = False
		else:
			c = c + 1
	res = ''
	if not key:
		if a == 0:
			key = False
			if b > 1:
				for j in range(len(st)):
					if st[j] in alph.upper():
						st = st[0:j] + 'a' + st[j + 1:]
						key = True
						break
			if c > 1 and (not key):
				for j in range(len(st)):
					if st[j] in digit:
						st = st[0:j] + 'a' + st[j + 1:]
						key = True
						break
		if b == 0:
			key = False
			if a > 1:
				for j in range(len(st)):
					if st[j] in alph:
						st = st[0:j] + 'A' + st[j + 1:]
						key = True
						break
			if c > 1 and (not key):
				for j in range(len(st)):
					if st[j] in digit:
						st = st[0:j] + 'A' + st[j + 1:]
						key = True
						break
		if c == 0:
			key = False
			if a > 1:
				for j in range(len(st)):
					if st[j] in alph:
						st = st[0:j] + '1' + st[j + 1:]
						key = True
						break
			if b > 1 and (not key):
				for j in range(len(st)):
					if st[j] in alph.upper():
						st = st[0:j] + '1' + st[j + 1:]
						key = True
						break
	print(st)


t = int(input())

def issmall(c):
	try:
		x = int(c)
		return False
	except Exception as e:
		return c.lower() == c

def islarge(c):
	try:
		x = int(c)
		return False
	except Exception as e:
		return c.upper() == c

def numeric(c):
	try:
		x = int(c)
		return True
	except Exception as e:
		return False
for _ in range(t):
	s = input()
	small = False
	large = False
	numeric = False
	for char in s:
		try:
			x = int(char)
			numeric = True
		except Exception as e:
			if char.lower() == char:
				small = True
			else:
				large = True
	if not small:
		if not large:
			answer = 'aA' + s[2:]
		elif not numeric:
			answer = 'a1' + s[2:]
		else:
			lar = False
			n = False
			answer = ''
			for i in range(len(s)):
				char = s[i]
				if islarge(char):
					if lar:
						answer += 'a' + s[i + 1:]
						break
					else:
						answer += char
						lar = True
				elif n:
					answer += 'a' + s[i + 1:]
					break
				else:
					answer += char
					n = True
	elif not large and (not numeric):
		answer = '1A' + s[2:]
	elif not numeric:
		lar = False
		sm = False
		answer = ''
		for i in range(len(s)):
			char = s[i]
			if islarge(char):
				if lar:
					answer += '1' + s[i + 1:]
					break
				else:
					answer += char
					lar = True
			elif sm:
				answer += '1' + s[i + 1:]
				break
			else:
				answer += char
				sm = True
	elif not large:
		sm = False
		n = False
		answer = ''
		for i in range(len(s)):
			char = s[i]
			if issmall(char):
				if sm:
					answer += 'A' + s[i + 1:]
					break
				else:
					answer += char
					sm = True
			elif n:
				answer += 'A' + s[i + 1:]
				break
			else:
				answer += char
				n = True
	else:
		answer = s
	print(answer)


for _ in range(int(input())):
	t = input()
	s = [i for i in t]
	(cd, cs, cc) = (0, 0, 0)
	cap = []
	sm = []
	di = []
	for i in range(len(s)):
		z = ord(s[i])
		if z >= 48 and z <= 57:
			cd += 1
			di.append(i)
		elif z >= 65 and z <= 91:
			cc += 1
			cap.append(i)
		elif z >= 97 and z <= 123:
			cs += 1
			sm.append(i)
	if cd > 0 and cc > 0 and (cs > 0):
		print(''.join(s))
	else:
		if cd == 0:
			if cc > 1:
				s[cap[0]] = '1'
				cap.pop(0)
				cc -= 1
				cd += 1
			elif cs > 1:
				s[sm[0]] = '1'
				sm.pop(0)
				cs -= 1
				cd += 1
		if cc == 0:
			if cd > 1:
				s[di[0]] = 'A'
				di.pop(0)
				cc += 1
				cd -= 1
			elif cs > 1:
				s[sm[0]] = 'A'
				sm.pop(0)
				cs -= 1
				cc += 1
		if cs == 0:
			if cd > 1:
				s[di[0]] = 'a'
				di.pop(0)
				cs += 1
				cd -= 1
			elif cc > 1:
				s[cap[0]] = 'a'
				cap.pop(0)
				cs += 1
				cc -= 1
		print(''.join(s))


for t in range(int(input())):
	s = list(map(str, input()))
	(l, u, d) = (0, 0, 0)
	st = ''
	for i in s:
		if '0' <= i <= '9':
			if d == 1:
				st += '2'
			else:
				st += '1'
				d = 1
		elif 'a' <= i <= 'z':
			if l == 1:
				st += '2'
			else:
				st += '1'
				l = 1
		elif u == 1:
			st += '2'
		else:
			st += '1'
			u = 1
	if l + u + d == 2:
		index = st.find('2')
		if l == 0:
			s[index] = 'a'
		elif u == 0:
			s[index] = 'A'
		else:
			s[index] = '1'
		print(*s, sep='')
	elif l + u + d == 1:
		index = st.find('22')
		if l == 1:
			(s[index], s[index + 1]) = ('A', '1')
		elif u == 1:
			(s[index], s[index + 1]) = ('a', '1')
		elif d == 1:
			(s[index], s[index + 1]) = ('A', 'a')
		print(*s, sep='')
	else:
		print(*s, sep='')


t = int(input())
for ii in range(t):
	(l, d, u) = (0, 0, 0)
	s = input()
	for tmp in list(s):
		if tmp.isnumeric():
			d += 1
		elif tmp.islower():
			l += 1
		elif tmp.isupper():
			u += 1
	if l == len(s):
		print('1A' + s[2:])
	elif d == len(s):
		print('aA' + s[2:])
	elif u == len(s):
		print('a1' + s[2:])
	elif l + d == len(s):
		ans = list(s)
		if l == 1:
			for (i, v) in enumerate(s, 0):
				if s[i].isnumeric():
					ans[i] = 'A'
					break
		elif d == 1:
			for (i, v) in enumerate(s, 0):
				if s[i].islower():
					ans[i] = 'A'
					break
		else:
			ans[0] = 'A'
		print(''.join(ans))
	elif l + u == len(s):
		ans = list(s)
		if l == 1:
			for (i, v) in enumerate(s, 0):
				if s[i].isupper():
					ans[i] = '1'
					break
		elif u == 1:
			for (i, v) in enumerate(s, 0):
				if s[i].islower():
					ans[i] = '1'
					break
		else:
			ans[0] = '1'
		print(''.join(ans))
	elif u + d == len(s):
		ans = list(s)
		if u == 1:
			for (i, v) in enumerate(s, 0):
				if s[i].isnumeric():
					ans[i] = 'a'
					break
		elif d == 1:
			for (i, v) in enumerate(s, 0):
				if s[i].isupper():
					ans[i] = 'a'
					break
		else:
			ans[0] = 'a'
		print(''.join(ans))
	else:
		print(s)


for _ in range(int(input().strip())):
	st = list(input().strip())
	(l, u, d) = ([], [], [])
	for i in range(len(st)):
		if st[i].isupper():
			u.append(i)
		elif st[i].islower():
			l.append(i)
		else:
			d.append(i)
	if len(l) > 0 and len(u) > 0 and (len(d) > 0):
		print(''.join(st))
	else:
		if len(l) > 0 and len(u) > 0:
			if len(l) > 1:
				st[l[0]] = '1'
			else:
				st[u[0]] = '1'
		elif len(u) > 0 and len(d) > 0:
			if len(u) > 1:
				st[u[0]] = 'a'
			else:
				st[d[0]] = 'a'
		elif len(l) > 0 and len(d) > 0:
			if len(l) > 1:
				st[l[0]] = 'A'
			else:
				st[d[0]] = 'A'
		elif len(l) > 0:
			st[l[0]] = 'A'
			st[l[1]] = '1'
		elif len(u) > 0:
			st[u[0]] = 'a'
			st[u[1]] = '1'
		else:
			st[d[0]] = 'A'
			st[d[1]] = 'a'
		print(''.join(st))


import string
t = int(input())
while t:
	d1 = {}
	l = [str(i) for i in range(9)]
	da = dict.fromkeys(string.ascii_lowercase, 0)
	dA = dict.fromkeys(string.ascii_uppercase, 0)
	d1 = d1.fromkeys(l, 0)
	(la, lA, l1) = ([], [], [])
	s = input()
	p = ''
	for i in range(len(s)):
		if da.get(s[i]) == None:
			pass
		else:
			da[s[i]] = 1
			la.append(i + 1)
		if dA.get(s[i]) == None:
			pass
		else:
			dA[s[i]] = 1
			lA.append(i + 1)
		if d1.get(s[i]) == None:
			pass
		else:
			d1[s[i]] = 1
			l1.append(i + 1)
	if sum(list(da.values())) != 0:
		if sum(list(d1.values())) != 0 and sum(list(dA.values())) != 0:
			p = s
			pass
		elif sum(list(d1.values())) == 0 and sum(list(dA.values())) != 0:
			if len(la) != 1:
				x = la[0] - 1
				p = s[:x] + '1' + s[x + 1:]
			else:
				y = lA[0] - 1
				p = s[:y] + '1' + s[y + 1:]
		elif sum(list(d1.values())) != 0 and sum(list(dA.values())) == 0:
			if len(la) != 1:
				x = la[0] - 1
				p = s[:x] + 'A' + s[x + 1:]
			else:
				y = l1[0] - 1
				p = s[:y] + 'A' + s[y + 1:]
		else:
			p = '1A' + s[2:]
	elif sum(list(d1.values())) != 0 and sum(list(dA.values())) != 0:
		if len(lA) != 1:
			x = lA[0] - 1
			p = s[:x] + 'a' + s[x + 1:]
		else:
			y = l1[0] - 1
			p = s[:y] + 'a' + s[y + 1:]
	elif sum(list(d1.values())) == 0 and sum(list(dA.values())) != 0:
		p = '1a' + s[2:]
	elif sum(list(d1.values())) != 0 and sum(list(dA.values())) == 0:
		p = 'aA' + s[2:]
	print(p)
	t = t - 1


n = int(input())

def cor(s):
	s = list(s)
	a = 0
	A = 0
	n = 0
	for j in range(len(s)):
		l = s[j]
		if ord('a') <= ord(l) and ord(l) <= ord('z'):
			a += 1
		elif ord('A') <= ord(l) and ord(l) <= ord('Z'):
			A += 1
		else:
			n += 1
	if a > 0 and A > 0 and (n > 0):
		return 1
	else:
		return 0

def solve(s):
	s = list(s)
	if cor(s) == 1:
		return s
	for j in range(len(s)):
		c = s[:]
		c[j] = 'a'
		if cor(c) == 1:
			return c
		c[j] = 'A'
		if cor(c) == 1:
			return c
		c[j] = '1'
		if cor(c) == 1:
			return c
	a = 0
	A = 0
	n = 0
	for j in range(len(s)):
		l = s[j]
		if ord('a') <= ord(l) and ord(l) <= ord('z'):
			a += 1
		elif ord('A') <= ord(l) and ord(l) <= ord('Z'):
			A += 1
		else:
			n += 1
	if a == 0 and A == 0:
		s[0] = 'a'
		s[1] = 'A'
		return s
	if a == 0 and n == 0:
		s[0] = 'a'
		s[1] = '1'
		return s
	else:
		s[0] = 'A'
		s[1] = '1'
		return s
for i in range(n):
	print(*solve(input()), sep='')


def istrue(s):
	isup = False
	islwn = False
	isdec = False
	for i in s:
		if i.isdecimal():
			isdec = True
		if i.isupper():
			isup = True
		if i.islower():
			islwn = True
	if isup and islwn and isdec:
		return True
	else:
		return False

def convert_base(num, to_base=3, from_base=10):
	if isinstance(num, str):
		n = int(num, from_base)
	else:
		n = int(num)
	alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	if n < to_base:
		return alphabet[n]
	else:
		return convert_base(n // to_base, to_base) + alphabet[n % to_base]

def maxthree(n):
	x = 1
	f = 0
	for i in range(0, n):
		f += 2 * x
		x = x * 3
	return f

def main(s):
	fl = False
	s_arr = []
	for i in range(0, len(s) + 1):
		if i == 0:
			if istrue(s):
				return s
		else:
			for y in range(0, maxthree(i) + 1):
				arr = [0 * x for x in range(0, i)]
				p = 0
				for o in convert_base(y):
					arr[p] += int(o)
					p += 1
				for r in range(0, len(s) - i + 1):
					s_arr = list(s)
					for g in range(r, r + i):
						if arr[g - r] == 0:
							s_arr[g] = '1'
						elif arr[g - r] == 1:
							if s_arr[g].isdecimal():
								s_arr[g] = 'a'
							else:
								s_arr[g] = s_arr[g].casefold()
						elif arr[g - r] == 2:
							if s_arr[g].isdecimal():
								s_arr[g] = 'A'
							else:
								s_arr[g] = s_arr[g].capitalize()
					if istrue(s_arr):
						fl = True
						break
				if fl:
					break
			if fl:
				break
	f = ''.join(s_arr)
	return f
m = int(input())
sin = []
for t in range(0, m):
	sin.append(input())
	sin[t] = main(sin[t])
for t in range(0 + 0, m):
	print(sin[t])


for _ in range(int(input())):
	s = input()
	r = ''
	(a, b, c) = [0] * 3
	for x in s:
		a += x.isdigit()
		b += x.islower()
		c += x.isupper()
	if a and b and c:
		r = s
	if a and b and (not c):
		(A, B) = (0, 0)
		for (i, x) in enumerate(s):
			if x.isdigit():
				A += 1
			else:
				B += 1
			if A > 1 or B > 1:
				r += 'A'
				r += s[i + 1:]
				break
			r += x
	if a and c and (not b):
		(A, C) = (0, 0)
		for (i, x) in enumerate(s):
			if x.isdigit():
				A += 1
			else:
				C += 1
			if A > 1 or C > 1:
				r += 'a'
				r += s[i + 1:]
				break
			r += x
	if b and c and (not a):
		(B, C) = (0, 0)
		for (i, x) in enumerate(s):
			if x.islower():
				B += 1
			else:
				C += 1
			if B > 1 or C > 1:
				r += '1'
				r += s[i + 1:]
				break
			r += x
	if a and (not any([b, c])):
		r = 'aA' + s[2:]
	if b and (not any([a, c])):
		r = '1A' + s[2:]
	if c and (not any([a, b])):
		r = '1a' + s[2:]
	print(r)


n = int(input())
for i in range(n):
	s = input()
	(k1, k2, k3) = (0, 0, 0)
	for i in range(len(s)):
		if '0' <= s[i] <= '9':
			k1 += 1
		elif 'A' <= s[i] <= 'Z':
			k2 += 1
		else:
			k3 += 1
	ans = ''
	for x in s:
		if '0' <= x <= '9':
			if k1 > 1:
				if k2 == 0:
					k1 -= 1
					k2 += 1
					ans += 'A'
				elif k3 == 0:
					k3 += 1
					k1 -= 1
					ans += 'a'
				else:
					ans += x
			else:
				ans += x
		elif 'A' <= x <= 'Z':
			if k2 > 1:
				if k1 == 0:
					k1 += 1
					k2 -= 1
					ans += '2'
				elif k3 == 0:
					k3 += 1
					k2 -= 1
					ans += 'z'
				else:
					ans += x
			else:
				ans += x
		elif k3 > 1:
			if k1 == 0:
				k1 += 1
				k3 -= 1
				ans += '2'
			elif k2 == 0:
				k2 += 1
				k3 -= 1
				ans += 'D'
			else:
				ans += x
		else:
			ans += x
	print(ans)


from collections import defaultdict
t = []
for i in range(int(input())):
	t.append(input())
v_const = {'upper': 'A', 'lower': 'a', 'numbers': '1'}
char_types = list(v_const.keys())
n_const = [str(i) for i in range(10)]
for p in t:
	indexes = defaultdict(list)
	for (i, v) in enumerate(p):
		if v in n_const:
			indexes['numbers'].append(i)
		elif v.islower():
			indexes['lower'].append(i)
		else:
			indexes['upper'].append(i)
	missing_arrays = {key: None for key in char_types if key not in indexes}
	keys = list(missing_arrays.keys())
	if len(keys) == 0:
		print(p)
	elif len(keys) == 1:
		for (key, val) in indexes.items():
			if len(val) > 1:
				missing_arrays[keys[0]] = val[0]
				break
		n_p = list(p)
		n_p[missing_arrays[keys[0]]] = v_const[keys[0]]
		print(''.join(n_p))
	else:
		n_p = list(p)
		n_p[0] = v_const[keys[0]]
		n_p[1] = v_const[keys[1]]
		print(''.join(n_p))


n = int(input())
for i in range(n):
	s = input()
	a = 0
	b = 0
	c = 0
	for j in range(len(s)):
		z = ord(s[j])
		if z <= 122 and z >= 97:
			a = a + 1
			k = j
		elif z >= 65 and z <= 90:
			b = b + 1
			l = j
		else:
			c = c + 1
			m = j
	if a * b * c == 0:
		if a == 0:
			if b == 0:
				s = s[0:len(s) - 2] + 'aA'
			elif c == 0:
				s = s[0:len(s) - 2] + 'a5'
			elif b > c:
				s = s[0:l] + 'a' + s[l + 1:]
			else:
				s = s[0:m] + 'a' + s[m + 1:]
		elif b == 0:
			if c == 0:
				s = s[0:len(s) - 2] + 'A5'
			elif a > c:
				s = s[0:k] + 'A' + s[k + 1:]
			else:
				s = s[0:m] + 'A' + s[m + 1:]
		elif a > b:
			s = s[0:k] + '5' + s[k + 1:]
		else:
			s = s[0:l] + '5' + s[l + 1:]
	print(s)


t = int(input())
for _ in range(t):
	s = list(input())
	num = False
	up = False
	down = False
	for i in s:
		if i.isupper():
			up = True
		elif i.islower():
			down = True
		elif i.isdigit():
			num = True
		if num and down and up:
			break
	n = len(s)
	if num:
		if up:
			if down:
				print(''.join(s))
			else:
				num = False
				up = False
				for i in range(n):
					if s[i].isupper():
						if not up:
							up = True
						else:
							s[i] = s[i].lower()
							break
					elif s[i].isdigit():
						if not num:
							num = True
						else:
							s[i] = 'a'
							break
				print(''.join(s))
		elif down:
			down = False
			num = False
			for i in range(n):
				if s[i].isdigit():
					if not num:
						num = True
					else:
						s[i] = 'A'
						break
				elif s[i].islower():
					if not down:
						down = True
					else:
						s[i] = s[i].upper()
						break
			print(''.join(s))
		else:
			print('Ab' + ''.join(s[2:]))
	elif down:
		if up:
			up = False
			down = False
			for i in range(n):
				if s[i].isupper():
					if not up:
						up = True
					else:
						s[i] = '4'
						break
				elif s[i].islower():
					if not down:
						down = True
					else:
						s[i] = '4'
						break
			print(''.join(s))
		else:
			print('A4' + ''.join(s[2:]))
	elif up:
		print('a4' + ''.join(s[2:]))
	else:
		print('Ab4' + ''.join(s[2:]))


n = int(input())
mna = set('qwertyuioplkjhgfdsazxcvbnm')
mnA = set('QWERTYUIOPLKJHGFDSAZXCVBNM')
mn0 = set('0123456789')
for i in range(n):
	s = input()
	z = x = c = False
	g = h = j = 0
	for (ind, ch) in enumerate(s):
		if ch in mna:
			z = True
			g += 1
			r = ind
		elif ch in mnA:
			x = True
			h += 1
			t = ind
		else:
			y = ind
			j += 1
			c = True
	if z == x == c == True:
		print(s)
	elif z == False and x == False:
		print('Aa' + s[2:])
	elif z == False and c == False:
		print('a0' + s[2:])
	elif x == False and c == False:
		print('A0' + s[2:])
	elif z == False:
		if h >= 2:
			print(s[:t] + 'a' + s[t + 1:])
		else:
			print(s[:y] + 'a' + s[y + 1:])
	elif x == False:
		if g >= 2:
			print(s[:r] + 'A' + s[r + 1:])
		else:
			print(s[:y] + 'A' + s[y + 1:])
	elif c == False:
		if g >= 2:
			print(s[:r] + '0' + s[r + 1:])
		else:
			print(s[:t] + '0' + s[t + 1:])


import string
for _ in range(int(input())):
	sets = (set(string.ascii_lowercase), set(string.ascii_uppercase), set(string.digits))
	s = list(input())
	cnt = [0, 0, 0]
	for c in s:
		for i in range(3):
			if c in sets[i]:
				cnt[i] += 1
	indexes = list(filter(lambda x: cnt[x] == 0, range(3)))
	if len(indexes) == 1:
		target_set = sets[indexes[0]]
		for i in range(len(s)):
			converted = False
			for j in range(3):
				if s[i] in sets[j] and cnt[j] > 1:
					s[i] = target_set.pop()
					converted = True
					break
			if converted:
				break
	elif len(indexes) == 2:
		s[0] = sets[indexes[0]].pop()
		s[1] = sets[indexes[1]].pop()
	print(''.join(s))


def test():
	s = list(input())
	(a, A, d) = (0, 0, 0)
	for c in s:
		if 'a' <= c <= 'z':
			a += 1
		elif 'A' <= c <= 'Z':
			A += 1
		else:
			d += 1
	need = []
	if a == 0:
		need.append('a')
	if A == 0:
		need.append('A')
	if d == 0:
		need.append('0')
	l = len(need)
	for i in range(0, len(s) - l):
		x = []
		for j in range(i, i + l):
			if 'a' <= s[j] <= 'z':
				x.append(a)
			elif 'A' <= s[j] <= 'Z':
				x.append(A)
			else:
				x.append(d)
		if 1 not in x:
			for j in range(l):
				s[i + j] = need[j]
			break
	print(''.join(s))
t = int(input())
for _ in range(t):
	test()


for _ in [0] * int(input()):
	s = list(input())
	l = [-1] * 4
	r = range(len(s))
	for i in r:
		l[(s[i] > '9') + (s[i] > 'Z')] = i
	for i in r:
		j = l.index(-1)
		if j < 3 and i not in l:
			s[i] = '0As'[j]
			l[j] = i
	print(''.join(s))


a = int(input())
for i in range(a):
	s = list(input())
	(no, cap, sm) = (0, 0, 0)
	for i in s:
		if ord(i) >= 48 and ord(i) <= 57:
			no += 1
		elif ord(i) >= 65 and ord(i) <= 90:
			cap += 1
		else:
			sm += 1
	if no == 0:
		if cap >= 2:
			for i in range(len(s)):
				if ord(s[i]) >= 65 and ord(s[i]) <= 90:
					s[i] = '0'
					no += 1
					cap -= 1
					break
		elif sm >= 2:
			for i in range(len(s)):
				if ord(s[i]) > 90:
					s[i] = '0'
					no += 1
					sm -= 1
					break
	if cap == 0:
		if no >= 2:
			for i in range(len(s)):
				if ord(s[i]) >= 48 and ord(s[i]) <= 57:
					s[i] = 'A'
					cap += 1
					no -= 1
					break
		elif sm >= 2:
			for i in range(len(s)):
				if ord(s[i]) > 90:
					s[i] = 'A'
					cap += 1
					sm -= 1
					break
	if sm == 0:
		if cap >= 2:
			for i in range(len(s)):
				if ord(s[i]) >= 65 and ord(s[i]) <= 90:
					s[i] = 'a'
					cap -= 1
					sm += 1
					break
		elif no >= 2:
			for i in range(len(s)):
				if ord(s[i]) < 65:
					s[i] = 'a'
					no -= 1
					sm += 1
					break
	print(''.join((i for i in s)))


def changer(s):
	n_lwr = 0
	n_upp = 0
	n_digit = 0
	lwr_pos = []
	upp_pos = []
	digit_pos = []
	for i in range(len(s)):
		if 'a' <= s[i] <= 'z':
			lwr_pos = lwr_pos + [i]
	for i in range(len(s)):
		if 'A' <= s[i] <= 'Z':
			upp_pos = upp_pos + [i]
	for i in range(len(s)):
		if s[i].isdigit():
			digit_pos = digit_pos + [i]
	for i in s:
		if i.isdigit() == True:
			n_digit = n_digit + 1
		elif ord('a') <= ord(i) <= ord('z'):
			n_lwr = n_lwr + 1
		elif ord('A') <= ord(i) <= ord('Z'):
			n_upp = n_upp + 1
	l = [n_upp, n_lwr, n_digit]
	lst_s = []
	for i in s:
		lst_s = lst_s + [i]
	if l[0] == 0 and l[1] == 0:
		lst_s[0] = 'a'
		lst_s[1] = 'A'
	elif l[1] == 0 and l[2] == 0:
		lst_s[0] = '1'
		lst_s[1] = 'a'
	elif l[0] == 0 and l[2] == 0:
		lst_s[0] = '1'
		lst_s[1] = 'A'
	elif l[0] == 0:
		if l[1] > l[2]:
			lst_s[lwr_pos[0]] = 'A'
		else:
			lst_s[digit_pos[0]] = 'A'
	elif l[1] == 0:
		if l[0] > l[2]:
			lst_s[upp_pos[0]] = 'a'
		else:
			lst_s[digit_pos[0]] = 'a'
	elif l[2] == 0:
		if l[1] > l[0]:
			lst_s[lwr_pos[0]] = '1'
		else:
			lst_s[upp_pos[0]] = '1'
	s1 = ''
	for i in lst_s:
		s1 = s1 + i
	return s1
m = int(input())
l = []
l1 = []
for i in range(m):
	s = str(input())
	l = l + [s]
for i in range(len(l)):
	l[i] = changer(str(l[i]))
for i in l:
	print(i)


uppers = [chr(a) for a in range(65, 91)]
lowers = [chr(a) for a in range(97, 123)]
numbers = [chr(a) for a in range(48, 58)]
checks = [uppers, lowers, numbers]
p = [input() for _ in range(int(input()))]
for w in p:
	counts = [[], [], []]
	for (c, a) in enumerate(w):
		for b in range(3):
			if a in checks[b]:
				counts[b].append(c)
				break
	change = []
	for a in range(3):
		if len(counts[a]) == 0:
			change.append(a)
	if len(change) == 0:
		print(w)
	elif len(change) == 1:
		for a in range(3):
			if len(counts[a]) > 1:
				break
		output = ''
		changed = False
		for b in w:
			if not changed and b in checks[a]:
				output += checks[change[0]][0]
				changed = True
			else:
				output += b
		print(output)
	else:
		for a in range(3):
			if not a in change:
				rid = a
				break
		m = counts[rid][1] - counts[rid][0]
		a = [counts[rid][0], counts[rid][1]]
		for b in range(1, len(w) - 1):
			if counts[rid][b + 1] - counts[rid][b] < m:
				m = counts[rid][b + 1] - counts[rid][b]
				a = [counts[rid][b], counts[rid][b + 1]]
		output = ''
		changed = 0
		for (c, b) in enumerate(w):
			if c in a:
				output += checks[change[changed]][0]
				changed += 1
			else:
				output += b
		print(output)


for _ in range(int(input())):
	s = input()
	s = list(s)
	(a, b, c) = (0, 0, 0)
	A = []
	B = []
	C = []
	for i in range(len(s)):
		x = ord(s[i])
		if x >= 97:
			a += 1
			A.append(i)
		elif x >= 65:
			b += 1
			B.append(i)
		else:
			c += 1
			C.append(i)
	if a > 0 and b > 0 and (c > 0):
		for i in s:
			print(i, end='')
		print()
	else:
		if a > 1:
			l = A
			if b == 0:
				s[l[1]] = 'A'
				l.pop(1)
				b += 1
				a -= 1
			if c == 0:
				s[l[1]] = '1'
				l.pop(1)
				c += 1
				a -= 1
		if b > 1:
			l = B
			if a == 0:
				s[l[1]] = 'a'
				l.pop(1)
				a += 1
				b -= 1
			if c == 0:
				s[l[1]] = '1'
				l.pop(1)
				c += 1
				b -= 1
		if c > 1:
			l = C
			if a == 0:
				s[l[1]] = 'a'
				l.pop(1)
				a += 1
				c -= 1
			if b == 0:
				s[l[1]] = 'A'
				l.pop(1)
				b += 1
				c -= 1
		for i in s:
			print(i, end='')
		print()


import re
x = int(input())
for i in range(x):
	u = []
	l = []
	d = []
	s = input()
	for char in range(len(s)):
		if s[char].isdigit():
			d.append(char)
		if s[char].islower():
			l.append(char)
		if s[char].isupper():
			u.append(char)
	ls = list(s)
	if not u and (not l):
		ls[0] = 'A'
		ls[1] = 'a'
	elif not d and (not l):
		ls[0] = '1'
		ls[1] = 'a'
	elif not u and (not d):
		ls[0] = 'A'
		ls[1] = '1'
	elif len(u) > 1:
		if not l:
			ls[u[0]] = 'a'
		elif not d:
			ls[u[0]] = '1'
	elif len(d) > 1:
		if not l:
			ls[d[0]] = 'a'
		elif not u:
			ls[d[0]] = 'A'
	elif len(l) > 1:
		if not u:
			ls[l[0]] = 'A'
		elif not d:
			ls[l[0]] = '1'
	print(''.join(ls))


for _ in range(int(input())):
	s = list(input())
	a = []
	b = []
	c = []
	for i in range(len(s)):
		if s[i].isnumeric():
			a.append(i)
		elif s[i].isupper():
			b.append(i)
		else:
			c.append(i)
	if len(a) == 0:
		if len(b) > 1:
			s[b[0]] = '1'
		else:
			s[c[0]] = '1'
	if len(b) == 0:
		if len(a) > 1:
			s[a[0]] = 'A'
		else:
			s[c[1]] = 'A'
	if len(c) == 0:
		if len(b) > 1:
			s[b[1]] = 'a'
		else:
			s[a[1]] = 'a'
	print(''.join(s))


t = int(input())
for i in range(t):
	s = input()
	upper = 0
	lower = 0
	digit = 0
	n = len(s)
	for j in s:
		if j.isdigit():
			digit = digit + 1
		if j.islower():
			lower = lower + 1
		if j.isupper():
			upper = upper + 1
	if upper == 0 and lower != 0 and (digit != 0):
		res = ''
		if lower >= digit:
			flag = 0
			for j in s:
				if j.islower() and flag == 0:
					flag = 1
					res = res + j.upper()
				else:
					res = res + j
		else:
			flag = 0
			for j in s:
				if j.isdigit() and flag == 0:
					flag = 1
					res = res + 'A'
				else:
					res = res + j
		print(res)
	elif lower == 0 and upper != 0 and (digit != 0):
		res = ''
		if upper >= digit:
			flag = 0
			for j in s:
				if j.isupper() and flag == 0:
					flag = 1
					res = res + j.lower()
				else:
					res = res + j
		else:
			flag = 0
			for j in s:
				if j.isdigit() and flag == 0:
					flag = 1
					res = res + 'a'
				else:
					res = res + j
		print(res)
	elif digit == 0 and lower != 0 and (upper != 0):
		res = ''
		if upper >= lower:
			flag = 0
			for j in s:
				if j.isupper() and flag == 0:
					flag = 1
					res = res + '1'
				else:
					res = res + j
		else:
			flag = 0
			for j in s:
				if j.islower() and flag == 0:
					flag = 1
					res = res + '1'
				else:
					res = res + j
		print(res)
	elif lower == 0 and upper == 0:
		res = 'aB' + s[2:n]
		print(res)
	elif lower == 0 and digit == 0:
		res = 'a1' + s[2:n]
		print(res)
	elif upper == 0 and digit == 0:
		res = 'A1' + s[2:n]
		print(res)
	else:
		print(s)


t = int(input())
result = []
low = 'abcdefghijklmnopqrstuvwxyz'
upp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
number = '0123456789'
for i in range(t):
	is_lower = 0
	is_upper = 0
	is_number = 0
	s = input()
	for i in s:
		if i in low:
			is_lower += 1
		elif i in number:
			is_number += 1
		elif i in upp:
			is_upper += 1
	if is_lower > 0 and is_upper > 0 and (is_number > 0):
		print(s)
	elif is_lower == 0 and is_upper == 0:
		print('aA' + s[2:])
	elif is_lower == 0 and is_number == 0:
		print('a1' + s[2:])
	elif is_upper == 0 and is_number == 0:
		print('A1' + s[2:])
	elif is_lower == 0:
		if is_upper > 1:
			for i in range(len(s)):
				if s[i] in upp:
					print(s[:i] + 'a' + s[i + 1:])
					break
		else:
			for i in range(len(s)):
				if s[i] in number:
					print(s[:i] + 'a' + s[i + 1:])
					break
	elif is_upper == 0:
		if is_lower > 1:
			for i in range(len(s)):
				if s[i] in low:
					print(s[:i] + 'A' + s[i + 1:])
					break
		else:
			for i in range(len(s)):
				if s[i] in number:
					print(s[:i] + 'A' + s[i + 1:])
					break
	elif is_number == 0:
		if is_lower > 1:
			for i in range(len(s)):
				if s[i] in low:
					print(s[:i] + '1' + s[i + 1:])
					break
		else:
			for i in range(len(s)):
				if s[i] in upp:
					print(s[:i] + '1' + s[i + 1:])
					break


import string

def rep(s, a, b):
	for i in range(len(s)):
		if s[i] in a:
			s = s[:i] + [b[0]] + s[i + 1:]
			return ''.join(s)
	assert False
T = int(input())
for i in range(T):
	s = list(input())
	c1 = 0
	c2 = 0
	c3 = 0
	for c in s:
		if c in string.ascii_lowercase:
			c1 += 1
		if c in string.ascii_uppercase:
			c2 += 1
		if c in string.digits:
			c3 += 1
	if c2 == 0 and c3 == 0:
		print('A0' + ''.join(s[2:]))
	elif c1 == 0 and c3 == 0:
		print('a0' + ''.join(s[2:]))
	elif c1 == 0 and c2 == 0:
		print('aA' + ''.join(s[2:]))
	elif c1 == 0:
		if c2 > 1:
			print(rep(s, string.ascii_uppercase, string.ascii_lowercase))
		elif c3 > 1:
			print(rep(s, string.digits, string.ascii_lowercase))
	elif c2 == 0:
		if c1 > 1:
			print(rep(s, string.ascii_lowercase, string.ascii_uppercase))
		elif c3 > 1:
			print(rep(s, string.digits, string.ascii_uppercase))
	elif c3 == 0:
		if c1 > 1:
			print(rep(s, string.ascii_lowercase, string.digits))
		elif c2 > 1:
			print(rep(s, string.ascii_uppercase, string.digits))
	else:
		print(''.join(s))


t = int(input())

def charToGroup(c):
	if 'a' <= c <= 'z':
		return 0
	elif 'A' <= c <= 'Z':
		return 1
	else:
		return 2

def groupToChar(g):
	return 'a' if g == 0 else 'B' if g == 1 else '3'
for i in range(t):
	s = input()
	cs = [0] * 3
	poses = [-1] * 3
	for (i, c) in enumerate(s):
		g = charToGroup(c)
		cs[g] += 1
		poses[g] = i
	types = (cs[0] > 0) + (cs[1] > 0) + (cs[2] > 0)
	if types == 3:
		print(s)
	elif types == 2:
		ag = 0 if cs[0] == 0 else 1 if cs[1] == 0 else 2
		mg = 0 if cs[0] >= 2 else 1 if cs[1] >= 2 else 2
		print(s[0:poses[mg]] + groupToChar(ag) + s[poses[mg] + 1:])
	else:
		pg = 0 if cs[0] >= 1 else 1 if cs[1] >= 1 else 2
		print(groupToChar((pg + 1) % 3) + groupToChar((pg + 2) % 3) + s[2:])


t = int(input())
while t > 0:
	t = t - 1
	s = input()
	(a, b, c) = (0, 0, 0)
	for i in s:
		if 'a' <= i <= 'z':
			a = 1
		elif 'A' <= i <= 'Z':
			b = 1
		elif 0 <= int(i) <= 9:
			c = 1
	if a == 1 and b == 1 and (c == 1):
		print(s)
	elif a == 0 and b == 0 and (c == 0):
		print('')
	elif b == 0 and c == 0:
		print('A7' + s[2:])
	elif a == 0 and b == 0:
		print('Sa' + s[2:])
	elif a == 0 and c == 0:
		print('s7' + s[2:])
	elif a == 0:
		if 'A' <= s[0] <= 'Z' and '0' <= s[1] <= '9' or ('A' <= s[1] <= 'Z' and '0' <= s[0] <= '9'):
			print(s[:2] + 'a' + s[3:])
		else:
			print('a' + s[1:])
	elif b == 0:
		if 'a' <= s[0] <= 'z' and '0' <= s[1] <= '9' or ('a' <= s[1] <= 'z' and '0' <= s[0] <= '9'):
			print(s[:2] + 'S' + s[3:])
		else:
			print('S' + s[1:])
	elif c == 0:
		if 'A' <= s[0] <= 'Z' and 'a' <= s[1] <= 'z' or ('A' <= s[1] <= 'Z' and 'a' <= s[0] <= 'z'):
			print(s[:2] + '7' + s[3:])
		else:
			print('7' + s[1:])


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]

def get_id(a):
	c_id = 2
	if 'a' <= a <= 'z':
		c_id = 0
	if 'A' <= a <= 'Z':
		c_id = 1
	return c_id
nb_test = read_int()
for _ in range(nb_test):
	replacement = ['a', 'A', '1']
	password = [x for x in input()]
	c_counts = [0] * 3
	for i in password:
		c_counts[get_id(i)] += 1
	for (i, v) in enumerate(password):
		ids = get_id(v)
		if c_counts[ids] > 1:
			for j in range(3):
				if not c_counts[j]:
					password[i] = replacement[j]
					c_counts[ids] -= 1
					c_counts[j] += 1
					break
	print(''.join(password))


t = int(input())
for i in range(t):
	s = list(input())
	(u, l, d) = (0, 0, 0)
	for i in s:
		if i.isdigit():
			d += 1
		if i.isupper():
			u += 1
		if i.islower():
			l += 1
	if d >= 1 and u >= 1 and (l >= 1):
		ans = ''
		for i in s:
			ans += i
		print(ans)
	else:
		if d == 0 and u >= 1 and (l >= 1):
			temp = s[0]
			if temp.isupper() and u == 1 or (temp.islower() and l == 1):
				s[1] = '1'
			else:
				s[0] = '1'
		elif d >= 1 and u == 0 and (l >= 1):
			temp = s[0]
			if temp.isdigit() and d == 1 or (temp.islower() and l == 1):
				s[1] = 'A'
			else:
				s[0] = 'A'
		elif d >= 1 and u >= 1 and (l == 0):
			temp = s[0]
			if temp.isupper() and u == 1 or (temp.isdigit() and d == 1):
				s[1] = 'a'
			else:
				s[0] = 'a'
		elif d == 0 and u == 0:
			s[0] = '1'
			s[1] = 'A'
		elif d == 0 and l == 0:
			s[0] = '1'
			s[1] = 'a'
		elif l == 0 and u == 0:
			s[0] = 'a'
			s[1] = 'A'
		ans = ''
		for i in s:
			ans += i
		print(ans)


for i in range(int(input())):
	s = list(input())
	maxf = ''
	(c1, cB, cs) = (0, 0, 0)
	(l, u, c, k, st, max) = (0, 0, 0, 0, 0, 0)
	for j in range(len(s)):
		if s[j] == '0' or s[j] == '1' or s[j] == '2' or (s[j] == '3') or (s[j] == '4') or (s[j] == '5') or (s[j] == '6') or (s[j] == '7') or (s[j] == '7') or (s[j] == '8') or (s[j] == '9'):
			c1 += 1
			l += 1
			if max < cB:
				max = cB
				maxf = 'B'
				st = j - cB
			if max < cs:
				maxf = 's'
				max = cs
				st = j - cs
			(cB, cs) = (0, 0)
		elif s[j].islower():
			u += 1
			cs += 1
			if max < cB:
				maxf = 'B'
				max = cB
				st = j - cB
			if max < c1:
				max = c1
				maxf = '1'
				st = j - c1
			(cB, c1) = (0, 0)
		else:
			c += 1
			cB += 1
			if max < cs:
				max = cs
				maxf = 's'
				st = j - cs
			if max < c1:
				maxf = '1'
				max = c1
				st = j - c1
			(cs, c1) = (0, 0)
	if max < cs:
		max = cs
		st = len(s) - cs
	if max < c1:
		max = c1
		st = len(s) - c1
	if max < cB:
		max = cB
		st = len(s) - cB
	if l == 0 or u == 0 or c == 0:
		sd = 0
		if max >= 3:
			if l == 0:
				s[st] = '1'
				sd += 1
			if u == 0:
				s[st + sd] = 'a'
				sd += 1
			if c == 0:
				s[st + sd] = 'A'
		else:
			if l == 0:
				s[st] = '1'
				sd += 1
			if u == 0:
				s[st + sd] = 'a'
				sd += 1
			if c == 0:
				s[st + sd] = 'A'
	print(''.join(s))


import re
lowerReg = re.compile('^[a-z]+$')

def ISlower(s):
	return lowerReg.match(s) is not None
upperReg = re.compile('^[A-Z]+$')

def ISupper(s):
	return upperReg.match(s) is not None
n = int(input())
pws = [input() for _ in range(n)]
for p in pws:
	(lower, upper, num) = ([], [], [])
	for x in range(len(p)):
		if ISlower(p[x]):
			lower.append(x)
		elif ISupper(p[x]):
			upper.append(x)
		else:
			num.append(x)
	if 0 < len(lower) * len(upper) * len(num):
		print(p)
	else:
		rep = []
		if len(lower) == 0:
			rep.append('a')
		elif 1 < len(lower):
			target = lower[0]
		if len(upper) == 0:
			rep.append('A')
		elif 1 < len(upper):
			target = upper[0]
		if len(num) == 0:
			rep.append('1')
		elif 1 < len(num):
			target = num[0]
		if 1 < len(rep):
			print(rep[0] + rep[1] + p[2:])
		else:
			print(p[:target] + rep[0] + p[target + 1:])


import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
t = nu()
for it in range(t):
	s = input()
	x = []
	y = []
	z = []
	for i in range(len(s)):
		cc = ord(s[i])
		if cc >= 48 and cc <= 57:
			x.append(i)
		if cc >= 65 and cc <= 90:
			y.append(i)
		if cc >= 97 and cc <= 122:
			z.append(i)
	if len(x) > 0 and len(y) > 0 and (len(z) > 0):
		print(s)
	else:
		pp = ''
		if len(x) > 0:
			if len(y) > 0:
				if len(x) > len(y):
					xx = False
					for i in range(len(s)):
						if xx == False and ord(s[i]) >= 48 and (ord(s[i]) <= 57):
							pp = pp + 'a'
							xx = True
						else:
							pp += s[i]
				else:
					xx = False
					for i in range(len(s)):
						if xx == False and ord(s[i]) >= 65 and (ord(s[i]) <= 90):
							pp = pp + 'a'
							xx = True
						else:
							pp += s[i]
			elif len(z) > 0:
				if len(x) > len(z):
					xx = False
					for i in range(len(s)):
						if xx == False and ord(s[i]) >= 48 and (ord(s[i]) <= 57):
							pp = pp + 'A'
							xx = True
						else:
							pp += s[i]
				else:
					xx = False
					for i in range(len(s)):
						if xx == False and ord(s[i]) >= 97 and (ord(s[i]) <= 122):
							pp = pp + 'A'
							xx = True
						else:
							pp += s[i]
			else:
				pp = s[0:x[len(x) - 2]] + 'A' + 'a'
		elif len(y) > 0:
			if len(z) > 0:
				if len(y) > len(z):
					pp = s[0:y[len(y) - 1]] + '1' + s[y[len(y) - 1] + 1:]
				else:
					pp = s[0:z[len(z) - 1]] + '1' + s[z[len(z) - 1] + 1:]
			else:
				pp = s[0:y[len(y) - 2]] + '1' + 'a'
		else:
			pp = s[0:z[len(z) - 2]] + '1' + 'A'
		print(pp)


from collections import defaultdict
t = int(input())
for i in range(t):
	freq = {'l': 0, 'U': 0, '1': 0}
	index = defaultdict(list)
	s = list(input())
	for j in range(len(s)):
		if s[j].islower():
			freq['l'] += 1
			index['l'].append(j)
		elif s[j].isupper():
			freq['U'] += 1
			index['U'].append(j)
		else:
			freq['1'] += 1
			index['1'].append(j)
	if 0 not in freq.values():
		print(''.join(s))
	elif list(freq.values()).count(0) == 1:
		max_freq = max(freq.items(), key=lambda x: x[1])
		min_freq = min(freq.items(), key=lambda x: x[1])
		s[index[max_freq[0]][0]] = min_freq[0]
		print(''.join(s))
	elif freq['l'] > 0:
		print('1A' + ''.join(s[2:]))
	elif freq['U'] > 0:
		print('1a' + ''.join(s[2:]))
	else:
		print('aA' + ''.join(s[2:]))


from sys import stdin, stdout
import cProfile, math
from collections import Counter
printHeap = str()
test = False
memory_constrained = False

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def test_print(output):
	if test:
		stdout.write(str(output) + '\n')

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def main():
	for _ in range(get_int()):
		lcase = list()
		ucase = list()
		digit = list()
		st = list(stdin.readline().strip())
		j = 0
		for i in st:
			if str(i).isupper():
				ucase.append(j)
			elif str(i).islower():
				lcase.append(j)
			else:
				digit.append(j)
			j += 1
		if len(ucase) == 0:
			if len(lcase) > 1:
				st[lcase[0]] = 'J'
				lcase.pop(0)
			else:
				st[digit[0]] = 'K'
				digit.pop(0)
		if len(lcase) == 0:
			if len(ucase) > 1:
				st[ucase[0]] = 'j'
				ucase.pop(0)
			else:
				st[digit[0]] = 'k'
				digit.pop(0)
		if len(digit) == 0:
			if len(lcase) > 1:
				st[lcase[0]] = '1'
			else:
				st[ucase[0]] = '0'
		display(''.join(st))
cProfile.run('main()') if test else main()


T = int(input())
hs = [{chr(x) for x in range(ord('0'), ord('9') + 1, 1)}, {chr(x) for x in range(ord('a'), ord('z') + 1, 1)}, {chr(x) for x in range(ord('A'), ord('Z') + 1, 1)}]
hch = ['1', 'a', 'A']
for t in range(T):
	s = input()
	c = [0] * 3
	for i in range(len(s)):
		if s[i] in hs[0]:
			c[0] += 1
		elif s[i] in hs[1]:
			c[1] += 1
		else:
			c[2] += 1
	if c.count(0) == 0:
		print(s)
		continue
	ls = list(s.strip())
	if c.count(0) == 2:
		ip = 0
		for hi in range(3):
			if c[hi] == 0:
				ls[ip] = hch[hi]
				ip += 1
		print(*ls, sep='')
		continue
	iipos = 0
	while c[iipos] < 2:
		iipos += 1
	ip = 0
	while ls[ip] not in hs[iipos]:
		ip += 1
	ls[ip] = hch[c.index(0)]
	print(*ls, sep='')
	continue


for _ in range(int(input())):
	(C, s) = ({'0': 0, 'A': 0, 'a': 0}, input())
	first = '0' if s[0].isdigit() else 'A' if s[0].isupper() else 'a'
	last = '0' if s[-1].isdigit() else 'A' if s[-1].isupper() else 'a'
	for ch in s:
		if ch.isdigit():
			C['0'] += 1
		elif ch.isupper():
			C['A'] += 1
		else:
			C['a'] += 1
	zeros = sum((not C[x] for x in '0Aa'))
	if zeros == 2:
		print(''.join(set('0Aa') - {first}) + s[2:])
	elif zeros == 1:
		if C[first] > 1:
			print(''.join((x for (x, c) in C.items() if c == 0)) + s[1:])
		else:
			print(s[:-1] + ''.join((x for (x, c) in C.items() if c == 0)))
	else:
		print(s)


from sys import stdin
input = stdin.readline

def is_good(arr):
	digit = False
	upper = False
	lower = False
	for c in arr:
		if c.isdigit():
			digit = True
		elif c.isupper():
			upper = True
		else:
			lower = True
	return digit and upper and lower

def solve():
	s = list(input().rstrip())
	if is_good(s):
		print(*s, sep='')
		return
	for i in range(len(s)):
		x = s[i]
		s[i] = '1'
		if is_good(s):
			print(*s, sep='')
			return
		s[i] = 'a'
		if is_good(s):
			print(*s, sep='')
			return
		s[i] = 'A'
		if is_good(s):
			print(*s, sep='')
			return
		s[i] = x
	for i in range(len(s) - 1):
		x = s[i]
		y = s[i + 1]
		s[i] = '1'
		s[i + 1] = 'a'
		if is_good(s):
			print(*s, sep='')
			return
		s[i] = '1'
		s[i + 1] = 'A'
		if is_good(s):
			print(*s, sep='')
			return
		s[i] = 'a'
		s[i + 1] = 'A'
		if is_good(s):
			print(*s, sep='')
			return
		s[i] = x
		s[i + 1] = y
t = int(input())
for _ in range(t):
	solve()


n = int(input())
for i in range(n):
	s = input()
	(a, b, c) = (0, 0, 0)
	for (j, x) in enumerate(s):
		if x >= 'a' and x <= 'z':
			a += 1
		elif x >= 'A' and x <= 'Z':
			b += 1
		else:
			c += 1
	if a == 0 and b > 0 and (c > 0):
		if b == 1 and c > 1:
			if s[0] >= 'A' and s[0] <= 'Z':
				print(s[0] + 'a' + s[2:])
			else:
				print('a' + s[1:])
		elif b > 1 and c == 1:
			if s[0] >= 'A' and s[0] <= 'Z':
				print('a' + s[1:])
			else:
				print(s[0] + 'a' + s[2:])
		else:
			print('a' + s[1:])
	elif a > 0 and b == 0 and (c > 0):
		if a == 1 and c > 1:
			if s[0] >= 'a' and s[0] <= 'z':
				print(s[0] + 'A' + s[2:])
			else:
				print('A' + s[1:])
		elif a > 1 and c == 1:
			if s[0] >= 'a' and s[0] <= 'z':
				print('A' + s[1:])
			else:
				print(s[0] + 'A' + s[2:])
		else:
			print('A' + s[1:])
	elif a > 0 and b > 0 and (c == 0):
		if a == 1 and b > 1:
			if s[0] >= 'a' and s[0] <= 'z':
				print(s[0] + '1' + s[2:])
			else:
				print('1' + s[1:])
		elif a > 1 and b == 1:
			if s[0] >= 'a' and s[0] <= 'z':
				print('1' + s[1:])
			else:
				print(s[0] + '1' + s[2:])
		else:
			print('1' + s[1:])
	elif a == 0 and b == 0 and (c > 0):
		print('a' + 'A' + s[2:])
	elif a == 0 and b > 0 and (c == 0):
		print('a' + '1' + s[2:])
	elif a > 0 and b == 0 and (c == 0):
		print('A' + '1' + s[2:])
	else:
		print(s)


from collections import defaultdict
n = int(input())
for i in range(n):
	s = input()
	d = defaultdict(int)
	for j in s:
		if j.isupper():
			d['u'] += 1
		elif j.islower():
			d['l'] += 1
		else:
			d['d'] += 1
	res = list(s)
	if d['u'] == 0 and d['l'] == 0:
		res[0] = 'a'
		res[1] = 'A'
	elif d['u'] == 0 and d['d'] == 0:
		res[0] = 'A'
		res[1] = '5'
	elif d['l'] == 0 and d['d'] == 0:
		res[0] = 'a'
		res[1] = '5'
	elif d['l'] == 0:
		if d['d'] != 1 and d['u'] != 1:
			res[0] = 'a'
		elif d['d'] == 1:
			if s[0].isdigit():
				res[1] = 'a'
			else:
				res[0] = 'a'
		elif s[0].isupper():
			res[1] = 'a'
		else:
			res[0] = 'a'
	elif d['u'] == 0:
		if d['d'] != 1 and d['l'] != 1:
			res[0] = 'A'
		elif d['d'] == 1:
			if s[0].isdigit():
				res[1] = 'A'
			else:
				res[0] = 'A'
		elif s[0].islower():
			res[1] = 'A'
		else:
			res[0] = 'A'
	elif d['d'] == 0:
		if d['l'] != 1 and d['u'] != 1:
			res[0] = '5'
		elif d['l'] == 1:
			if s[0].islower():
				res[1] = '5'
			else:
				res[0] = '5'
		elif s[0].isupper():
			res[1] = '5'
		else:
			res[0] = '5'
	print(''.join(res))


n = int(input())
A = [input() for i in range(n)]
for S in A:
	lower = 0
	upper = 0
	digit = 0
	ans = S
	for (i, s) in enumerate(S):
		if s.islower():
			lower += 1
		elif s.isupper():
			upper += 1
		else:
			digit += 1
	if lower and upper and digit:
		print(S)
		continue
	B = []
	if lower == 0:
		B.append('a')
	if upper == 0:
		B.append('A')
	if digit == 0:
		B.append('1')
	C = 0
	if ans[C].islower() and lower == 1 or (ans[C].isupper() and upper == 1) or (ans[C].isnumeric() and digit == 1):
		C += 1
	for b in B:
		ans = ans[:C] + b + ans[C + 1:]
		C += 1
	print(ans)


for i in range(int(input())):
	s = input()
	a = 'abcdefghijklmnopqrstuvwxyz'
	a = list(a)
	b = '1234567890'
	b = list(b)
	c = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	c = list(c)
	nu = 0
	nl = 0
	nn = 0
	inum = 0
	ilower = 0
	iupper = 0
	for j in range(len(s)):
		if s[j] in a:
			nl += 1
			ilower = j
		elif s[j] in b:
			nn += 1
			inum = j
		elif s[j] in c:
			nu += 1
			iupper = j
	s = list(s)
	if nn >= 1 and nu >= 1 and (nl >= 1):
		print(''.join(s))
	elif nn >= 1 and nu >= 1 and (nl == 0):
		if nn > 1:
			s[inum] = 'a'
		else:
			s[iupper] = 'a'
		print(''.join(s))
	elif nn >= 1 and nl >= 1 and (nu == 0):
		if nn > 1:
			s[inum] = 'A'
		else:
			s[ilower] = 'A'
		print(''.join(s))
	elif nl >= 1 and nu >= 1 and (nn == 0):
		if nu > 1:
			s[iupper] = '1'
		else:
			s[ilower] = '1'
		print(''.join(s))
	elif nn >= 1 and nu == 0 and (nl == 0):
		s[0] = 'a'
		s[1] = 'A'
		print(''.join(s))
	elif nu >= 1 and nn == 0 and (nl == 0):
		s[0] = '1'
		s[1] = 'a'
		print(''.join(s))
	elif nl >= 1 and nn == 0 and (nu == 0):
		s[0] = '1'
		s[1] = 'A'
		print(''.join(s))


t = int(input())
for i in range(t):
	s = input()
	d = False
	u = False
	l = False
	digit = 0
	uc = 0
	lc = 0
	n = len(s)
	for j in range(n):
		if d is True and u is True and (l is True):
			break
		elif 48 <= ord(s[j]) <= 57:
			d = True
		elif 65 <= ord(s[j]) <= 90:
			u = True
		elif 97 <= ord(s[j]) <= 122:
			l = True
	else:
		for k in range(n):
			if 48 <= ord(s[k]) <= 57:
				digit += 1
				if digit >= 2 and u is False:
					s = s[0:k] + 'A' + s[k + 1:]
					u = True
				elif digit >= 2 and l is False:
					s = s[0:k] + 'a' + s[k + 1:]
					l = True
			elif 65 <= ord(s[k]) <= 90:
				uc += 1
				if uc >= 2 and d is False:
					s = s[0:k] + '0' + s[k + 1:]
					d = True
				elif uc >= 2 and l is False:
					s = s[0:k] + 'a' + s[k + 1:]
					l = True
			elif 97 <= ord(s[k]) <= 122:
				lc += 1
				if lc >= 2 and u is False:
					s = s[0:k] + 'A' + s[k + 1:]
					u = True
				elif lc >= 2 and d is False:
					s = s[0:k] + '0' + s[k + 1:]
					d = True
	print(s)


n = int(input())
a = [list(input()) for i in range(n)]
for i in range(n):
	s = a[i]
	res = [0, 0, 0]
	for j in range(len(s)):
		if ord(s[j]) < 65:
			res[2] += 1
		elif ord(s[j]) < 97:
			res[1] += 1
		else:
			res[0] += 1
	if res[0] == 0 and res[1] == 0:
		cnt = 0
		s[0] = 'a'
		s[1] = 'A'
	elif res[0] == 0 and res[2] == 0:
		s[0] = 'a'
		s[1] = '1'
	elif res[1] == 0 and res[2] == 0:
		s[0] = '1'
		s[1] = 'A'
	elif res[0] == 0:
		for j in range(len(s)):
			if ord(s[j]) >= 65 and res[1] > 1:
				s[j] = 'a'
				break
			elif ord(s[j]) < 65 and res[2] > 1:
				s[j] = 'a'
				break
	elif res[1] == 0:
		for j in range(len(s)):
			if ord(s[j]) >= 97 and res[0] > 1:
				s[j] = 'A'
				break
			elif ord(s[j]) < 65 and res[2] > 1:
				s[j] = 'A'
				break
	elif res[2] == 0:
		for j in range(len(s)):
			if ord(s[j]) >= 97 and res[0] > 1:
				s[j] = '1'
				break
			elif ord(s[j]) >= 65 and ord(s[j]) < 97 and (res[1] > 1):
				s[j] = '1'
				break
	for u in range(len(s)):
		print(s[u], end='')
	print()


for _ in range(int(input())):
	a = input()
	(dc, lc, uc) = (0, 0, 0)
	for i in a:
		if i.isdigit():
			dc += 1
		if i.islower():
			lc += 1
		if i.isupper():
			uc += 1
	n = len(a)
	if dc == 0:
		if lc == 0:
			a = 'a1' + a[2:]
		elif uc == 0:
			a = 'A1' + a[2:]
		elif lc == 1:
			for i in range(n):
				if not a[i].islower():
					a = a[:i] + '1' + a[i + 1:]
					break
		elif uc == 1:
			for i in range(n):
				if not a[i].isupper():
					a = a[:i] + '1' + a[i + 1:]
					break
		else:
			a = '1' + a[1:]
	elif lc == 0:
		if dc == 0:
			a = 'a1' + a[2:]
		elif uc == 0:
			a = 'Aa' + a[2:]
		elif dc == 1:
			for i in range(n):
				if not a[i].isdigit():
					a = a[:i] + 'a' + a[i + 1:]
					break
		elif uc == 1:
			for i in range(n):
				if not a[i].isupper():
					a = a[:i] + 'a' + a[i + 1:]
					break
		else:
			a = 'a' + a[1:]
	elif uc == 0:
		if lc == 0:
			a = 'aA' + a[2:]
		elif dc == 0:
			a = 'A1' + a[2:]
		elif lc == 1:
			for i in range(n):
				if not a[i].islower():
					a = a[:i] + 'A' + a[i + 1:]
					break
		elif dc == 1:
			for i in range(n):
				if not a[i].isdigit():
					a = a[:i] + 'A' + a[i + 1:]
					break
		else:
			a = 'A' + a[1:]
	print(a)


t = int(input())
subStr = 'aB1'

def isLower(x):
	if 'a' <= x and 'z' >= x:
		return True
	else:
		return False

def isUpper(x):
	if 'A' <= x and 'Z' >= x:
		return True
	else:
		return False

def isDegit(x):
	if '0' <= x and '9' >= x:
		return True
	else:
		return False

def move(x):
	if isLower(x):
		return 0
	elif isUpper(x):
		return 1
	elif isDegit(x):
		return 2

def calBits(x):
	ret = 0
	for i in range(3):
		if x & 1 << i:
			ret += 1
	return ret

def solve(s):
	l = [0 for _ in range(105)]
	r = [0 for _ in range(105)]
	l[0] = 1 << move(s[0])
	r[len(s) - 1] = 1 << move(s[len(s) - 1])
	for i in range(1, len(s)):
		l[i] = l[i - 1] | 1 << move(s[i])
	for i in range(len(s) - 1, -1, -1):
		r[i] = r[i + 1] | 1 << move(s[i])
	for i in range(3):
		for j in range(0, len(s) - i + 1):
			left = j
			right = j + i + 1
			if calBits(l[j] | r[right]) == 3 - i:
				cur = l[j] | r[right]
				append = ''
				for k in range(3):
					if 0 == cur & 1 << k:
						append += subStr[k]
				print(s[0:left + 1] + append + s[right:])
				return
for i in range(t):
	s = input()
	solve(s)


t = int(input())
for i in range(0, t):
	s = input()
	s = list(s)
	a = 0
	A = 0
	d = 0
	for j in range(len(s)):
		if 'a' <= s[j] <= 'z':
			a = a + 1
		elif 'A' <= s[j] <= 'Z':
			A = A + 1
		else:
			d = d + 1
	if a == 0:
		if A > 1:
			for k in range(len(s)):
				if 'A' <= s[k] <= 'Z':
					s[k] = 'a'
					break
		elif d > 1:
			for k in range(len(s)):
				if '0' <= s[k] <= '9':
					s[k] = 'a'
					break
	if A == 0:
		if a > 1:
			for k in range(len(s)):
				if 'a' <= s[k] <= 'z':
					s[k] = 'A'
					break
		elif d > 1:
			for k in range(len(s)):
				if '0' <= s[k] <= '9':
					s[k] = 'A'
					break
	if d == 0:
		if a > 1:
			for k in range(len(s)):
				if 'a' <= s[k] <= 'z':
					s[k] = '0'
					break
		elif A > 1:
			for k in range(len(s)):
				if 'A' <= s[k] <= 'Z':
					s[k] = '0'
					break
	print(''.join(s))


for _ in range(int(input())):
	s = list(input())
	l = u = d = 0
	for char in s:
		if char.isupper():
			u += 1
		elif char.islower():
			l += 1
		else:
			d += 1
	if l > 0 and u > 0 and (d > 0):
		print(''.join(s))
	else:
		if d == 0 and u == 0:
			s[0] = '0'
			s[1] = 'A'
		elif d == 0 and l == 0:
			s[0] = '0'
			s[1] = 'a'
		elif l == 0 and u == 0:
			s[0] = 'a'
			s[1] = 'A'
		elif d == 0:
			if u > l:
				for (i, char) in enumerate(s):
					if char.isupper():
						s[i] = '0'
						break
			else:
				for (i, char) in enumerate(s):
					if char.islower():
						s[i] = '0'
						break
		elif u == 0:
			if d > l:
				for (i, char) in enumerate(s):
					if char.isdigit():
						s[i] = 'A'
						break
			else:
				for (i, char) in enumerate(s):
					if char.islower():
						s[i] = 'A'
						break
		elif d > u:
			for (i, char) in enumerate(s):
				if char.isdigit():
					s[i] = 'a'
					break
		else:
			for (i, char) in enumerate(s):
				if char.isupper():
					s[i] = 'a'
					break
		print(''.join(s))


t = int(input())
while t:
	t = t - 1
	r = input()
	fl = 0
	fu = 0
	fd = 0
	r1 = ''
	for i in r:
		if i.isupper():
			fu = fu + 1
		elif i.islower():
			fl = fl + 1
		else:
			fd = fd + 1
	if fu and fd and fl:
		print(r)
		continue
	if fu == 0 and fl == 0:
		print('Aa' + r[2:])
		continue
	if fd == 0 and fl == 0:
		print('1a' + r[2:])
		continue
	if fu == 0 and fd == 0:
		print('1A' + r[2:])
		continue
	if fu == 0:
		f = 1
		r1 = ''
		for i in r:
			if i.islower() and fl > 1 and f:
				r1 = r1 + 'A'
				f = 0
			elif i.islower() != 1 and fd > 1 and f:
				r1 = r1 + 'A'
				f = 0
			else:
				r1 = r1 + i
		print(r1)
		continue
	if fl == 0:
		f = 1
		r1 = ''
		for i in r:
			if i.isupper() and fu > 1 and f:
				r1 = r1 + 'a'
				f = 0
			elif i.isupper() != 1 and fd > 1 and f:
				r1 = r1 + 'a'
				f = 0
			else:
				r1 = r1 + i
		print(r1)
		continue
	if fd == 0:
		f = 1
		r1 = ''
		for i in r:
			if i.islower() and fl > 1 and f:
				r1 = r1 + '1'
				f = 0
			elif i.isupper() and fu > 1 and f:
				r1 = r1 + '1'
				f = 0
			else:
				r1 = r1 + i
		print(r1)
		continue


def char_type(c):
	if c in set('0123456789'):
		return 0
	elif ord('a') <= ord(c) <= ord('z'):
		return 1
	else:
		return 2

def substitute(pwd):
	pwd_list = list(pwd)
	char_types = [char_type(c) for c in pwd]
	missing = set()
	for i in range(3):
		if i not in char_types:
			missing.add(i)
	counter = [0, 0, 0]
	for e in char_types:
		counter[e] += 1
	if len(missing) == 1:
		if 0 in missing:
			_max = 1 if counter[1] >= counter[2] else 2
			for i in range(len(pwd)):
				if char_types[i] == _max:
					pwd_list[i] = '0'
					return ''.join(pwd_list)
		if 1 in missing:
			_max = 0 if counter[0] >= counter[2] else 2
			for i in range(len(pwd)):
				if char_types[i] == _max:
					pwd_list[i] = 'a'
					return ''.join(pwd_list)
		if 2 in missing:
			_max = 0 if counter[0] >= counter[1] else 1
			for i in range(len(pwd)):
				if char_types[i] == _max:
					pwd_list[i] = 'A'
					return ''.join(pwd_list)
	elif len(missing) == 2:
		if 0 in missing and 1 in missing:
			pwd_list[:2] = ['0', 'a']
			return ''.join(pwd_list)
		if 1 in missing and 2 in missing:
			pwd_list[:2] = ['a', 'A']
			return ''.join(pwd_list)
		if 0 in missing and 2 in missing:
			pwd_list[:2] = ['0', 'A']
			return ''.join(pwd_list)
	else:
		return pwd

def main():
	n = int(input())
	passwords = [input() for _ in range(n)]
	for pwd in passwords:
		res = substitute(pwd)
		print(res)
main()


for _ in range(int(input())):
	s = input()
	n = len(s)
	u = l = d = 0
	for i in range(n):
		if s[i].islower():
			l += 1
		elif s[i].isupper():
			u += 1
		else:
			d += 1
	if l and u and d:
		print(s)
		continue
	st = ''
	if l == n:
		for i in range(n - 2):
			st += s[i]
		st += '1'
		st += 'D'
		print(st)
		continue
	if u == n:
		for i in range(n - 2):
			st += s[i]
		st += 't'
		st += '2'
		print(st)
		continue
	if d == n:
		for i in range(n - 2):
			st += s[i]
		st += 't'
		st += 'P'
		print(st)
		continue
	f = 0
	if l == 0 and d != 0 and (u != 0):
		f = 0
		if u > 1:
			for i in range(n):
				if s[i].isupper() and f == 0:
					st += 'i'
					f = 1
				else:
					st += s[i]
		elif d > 1:
			for i in range(n):
				if s[i].isdigit() and f == 0:
					st += 'p'
					f = 1
				else:
					st += s[i]
		print(st)
	elif d == 0 and l != 0 and (u != 0):
		f = 0
		if l > 1:
			for i in range(n):
				if s[i].islower() and f == 0:
					st += '1'
					f = 1
				else:
					st += s[i]
		elif u > 1:
			for i in range(n):
				if s[i].isupper() and f == 0:
					st += '2'
					f = 1
				else:
					st += s[i]
		print(st)
	elif u == 0 and l != 0 and (d != 0):
		if l > 1:
			for i in range(n):
				if s[i].islower() and f == 0:
					f = 1
					st += 'R'
				else:
					st += s[i]
		elif d > 1:
			for i in range(n):
				if s[i].isdigit() and f == 0:
					f = 1
					st += 'R'
				else:
					st += s[i]
		print(st)


def isvalid(c):
	lower = False
	upper = False
	number = False
	for j in c:
		if j.isupper():
			upper = True
		if j.islower():
			lower = True
		if j.isnumeric():
			number = True
	if upper and lower and number:
		return True
	else:
		return False
t = int(input())
for i in range(t):
	s = input()
	if isvalid(s):
		print(s)
	else:
		for j in range(len(s)):
			temp = s[:j] + 'a' + s[j + 1:]
			if isvalid(temp):
				s = temp
				break
			temp = s[:j] + 'A' + s[j + 1:]
			if isvalid(temp):
				s = temp
				break
			temp = s[:j] + '1' + s[j + 1:]
			if isvalid(temp):
				s = temp
				break
		if isvalid(s):
			print(s)
		elif s[2].islower():
			s = 'A1' + s[2:]
			print(s)
		elif s[2].isupper():
			s = 'a1' + s[2:]
			print(s)
		else:
			s = 'aA' + s[2:]
			print(s)


tc = int(input())
represent = []
number = '1'
lowcase = 'a'
upper = 'A'
for t in range(tc):
	islow = 0
	isup = 0
	isnum = 0
	ans = 0
	s = input()
	for z in s:
		if z.islower():
			represent.append(0)
			islow += 1
		elif z.isdigit():
			represent.append(1)
			isnum += 1
		elif z.isupper():
			represent.append(2)
			isup += 1
	if islow and isnum and isup:
		print(s)
	elif islow == 0 and isnum > 0 and (isup > 0):
		hasil = []
		ischanged = False
		if isnum > 1:
			for z in s:
				if z.isdigit() and (not ischanged):
					hasil.append(lowcase)
					ischanged = True
				else:
					hasil.append(z)
		else:
			for z in s:
				if z.isupper() and (not ischanged):
					hasil.append(lowcase)
					ischanged = True
				else:
					hasil.append(z)
		print(''.join(hasil))
	elif islow > 0 and isnum == 0 and (isup > 0):
		hasil = []
		ischanged = False
		if islow > 1:
			for z in s:
				if z.islower() and (not ischanged):
					hasil.append(number)
					ischanged = True
				else:
					hasil.append(z)
		else:
			for z in s:
				if z.isupper() and (not ischanged):
					hasil.append(number)
					ischanged = True
				else:
					hasil.append(z)
		print(''.join(hasil))
	elif islow > 0 and isnum > 0 and (isup == 0):
		hasil = []
		ischanged = False
		if isnum > 1:
			for z in s:
				if z.isdigit() and (not ischanged):
					hasil.append(upper)
					ischanged = True
				else:
					hasil.append(z)
		else:
			for z in s:
				if z.islower() and (not ischanged):
					hasil.append(upper)
					ischanged = True
				else:
					hasil.append(z)
		print(''.join(hasil))
	elif islow == 0 and isnum == 0:
		pos = (-1, -1)
		for z in range(1, len(s)):
			for x in range(0, len(s)):
				if x + z >= len(s):
					break
				if s[z].isupper() and s[z + x].isupper():
					pos = (x, z + x)
					break
			if pos != (-1, -1):
				break
		hasil = []
		for z in range(0, len(s)):
			if z == pos[0]:
				hasil.append(lowcase)
			elif z == pos[1]:
				hasil.append(number)
			else:
				hasil.append(s[z])
		print(''.join(hasil))
	elif islow == 0 and isup == 0:
		pos = (-1, -1)
		for z in range(1, len(s)):
			for x in range(0, len(s)):
				if x + z >= len(s):
					break
				if s[z].isdigit() and s[z + x].isdigit():
					pos = (x, z + x)
					break
			if pos != (-1, -1):
				break
		hasil = []
		for z in range(0, len(s)):
			if z == pos[0]:
				hasil.append(lowcase)
			elif z == pos[1]:
				hasil.append(upper)
			else:
				hasil.append(s[z])
		print(''.join(hasil))
	elif isnum == 0 and isup == 0:
		pos = (-1, -1)
		for z in range(1, len(s)):
			for x in range(0, len(s)):
				if x + z >= len(s):
					break
				if s[z].islower() and s[z + x].islower():
					pos = (x, z + x)
					break
			if pos != (-1, -1):
				break
		hasil = []
		for z in range(0, len(s)):
			if z == pos[0]:
				hasil.append(number)
			elif z == pos[1]:
				hasil.append(upper)
			else:
				hasil.append(s[z])
		print(''.join(hasil))


(d, u, l) = (0, 0, 0)

def isdigit(a):
	if a.isupper() == True or a.islower() == True:
		return False
	else:
		return True
for _ in range(int(input())):
	x = list(input())
	for i in x:
		if isdigit(i) == True:
			d += 1
		elif i.isupper() == True:
			u += 1
		else:
			l += 1
	if u == 0:
		if max(d, l) == l:
			for i in range(len(x)):
				if x[i].islower() == True:
					x[i] = 'A'
					break
		elif max(d, l) == d:
			for i in range(len(x)):
				if isdigit(x[i]) == True:
					x[i] = 'A'
					break
	if l == 0:
		if max(d, u) == u:
			for i in range(len(x)):
				if x[i].isupper() == True:
					x[i] = 'a'
					break
		elif max(d, u) == d:
			for i in range(len(x)):
				if isdigit(x[i]) == True:
					x[i] = 'a'
					break
	if d == 0:
		if max(l, u) == u:
			for i in range(len(x)):
				if x[i].isupper() == True:
					x[i] = '4'
					break
		elif max(l, u) == l:
			for i in range(len(x)):
				if x[i].islower() == True:
					x[i] = '4'
					break
	print(''.join(x))
	(d, u, l) = (0, 0, 0)


import math
t = int(input())
for i in range(t):
	s = input()
	s = list(s)
	n = len(s)
	c = 0
	sm = 0
	no = 0
	for j in range(n):
		if ord(s[j]) >= 97 and ord(s[j]) <= 122:
			sm = 1
		elif ord(s[j]) >= 65 and ord(s[j]) <= 90:
			c = 1
		else:
			no = 1
	if sm == 1 and c == 1 and (no == 1):
		for k in range(n):
			print(s[k], end='')
		print()
	elif sm + c + no == 1:
		if sm == 1:
			s[0] = '1'
			s[1] = 'A'
			for k in range(n):
				print(s[k], end='')
			print()
		elif c == 1:
			s[0] = '1'
			s[1] = 'a'
			for k in range(n):
				print(s[k], end='')
			print()
		else:
			s[0] = 'a'
			s[1] = 'A'
			for k in range(n):
				print(s[k], end='')
			print()
	else:
		if sm == 0:
			for j in range(n - 1):
				if ord(s[j]) >= 48 and ord(s[j]) <= 57 and (ord(s[j + 1]) >= 65) and (ord(s[j + 1]) <= 90):
					if j == n - 2:
						s[j - 1] = 'a'
					else:
						s[j + 2] = 'a'
					break
				elif ord(s[j + 1]) >= 48 and ord(s[j + 1]) <= 57 and (ord(s[j]) >= 65) and (ord(s[j]) <= 90):
					if j == n - 2:
						s[j - 1] = 'a'
					else:
						s[j + 2] = 'a'
					break
		elif no == 0:
			for j in range(n - 1):
				if ord(s[j]) >= 97 and ord(s[j]) <= 122 and (ord(s[j + 1]) >= 65) and (ord(s[j + 1]) <= 90):
					if j == n - 2:
						s[j - 1] = '1'
					else:
						s[j + 2] = '1'
					break
				elif ord(s[j + 1]) >= 97 and ord(s[j + 1]) <= 122 and (ord(s[j]) >= 65) and (ord(s[j]) <= 90):
					if j == n - 2:
						s[j - 1] = '1'
					else:
						s[j + 2] = '1'
					break
		elif c == 0:
			for j in range(n - 1):
				if ord(s[j]) >= 48 and ord(s[j]) <= 57 and (ord(s[j + 1]) >= 97) and (ord(s[j + 1]) <= 122):
					if j == n - 2:
						s[j - 1] = 'A'
					else:
						s[j + 2] = 'A'
					break
				elif ord(s[j + 1]) >= 48 and ord(s[j + 1]) <= 57 and (ord(s[j]) >= 97) and (ord(s[j]) <= 122):
					if j == n - 2:
						s[j - 1] = 'A'
					else:
						s[j + 2] = 'A'
					break
		for k in range(n):
			print(s[k], end='')
		print()


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def main():
	(T,) = map(int, input().split(' '))
	for _ in range(T):
		s = input()
		(cu, cl, cd) = (0, 0, 0)
		for x in s:
			if 'a' <= x <= 'z':
				cl += 1
			elif 'A' <= x <= 'Z':
				cu += 1
			else:
				cd += 1
		if cu > 0 and cl > 0 and (cd > 0):
			print(s)
		elif cu == 0:
			if cl == 0:
				print('Aa' + s[2:])
			elif cd == 0:
				print('A0' + s[2:])
			else:
				for i in range(len(s)):
					if 'a' <= s[i] <= 'z' and cl >= 2 or ('0' <= s[i] <= '9' and cd >= 2):
						print(s[:i] + 'A' + s[i + 1:])
						break
		elif cl == 0:
			if cd == 0:
				print('a0' + s[2:])
			else:
				for i in range(len(s)):
					if 'A' <= s[i] <= 'Z' and cu >= 2 or ('0' <= s[i] <= '9' and cd >= 2):
						print(s[:i] + 'a' + s[i + 1:])
						break
		else:
			for i in range(len(s)):
				if 'A' <= s[i] <= 'Z' and cu >= 2 or ('a' <= s[i] <= 'z' and cl >= 2):
					print(s[:i] + '0' + s[i + 1:])
					break
main()


import string
t = int(input())
for _ in range(t):
	s = input()
	(a, b, c, p, q) = (0, 0, 0, 0, 0)
	n = len(s)
	for x in string.ascii_lowercase:
		if x in s:
			a += 1
	for x in string.ascii_uppercase:
		if x in s:
			b += 1
	for x in string.digits:
		if x in s:
			c += 1
	if a * b * c > 0:
		print(s)
	elif a == 0 and b * c > 0:
		for i in range(n):
			if s[i] in string.ascii_uppercase:
				p += 1
				if p > 1:
					print(s[:i] + 'a' + s[i + 1:])
					break
			else:
				q += 1
				if q > 1:
					print(s[:i] + 'a' + s[i + 1:])
					break
	elif b == 0 and a * c > 0:
		for i in range(n):
			if s[i] in string.ascii_lowercase:
				p += 1
				if p > 1:
					print(s[:i] + 'A' + s[i + 1:])
					break
			else:
				q += 1
				if q > 1:
					print(s[:i] + 'A' + s[i + 1:])
					break
	elif c == 0 and a * b > 0:
		for i in range(n):
			if s[i] in string.ascii_lowercase:
				p += 1
				if p > 1:
					print(s[:i] + '0' + s[i + 1:])
					break
			else:
				q += 1
				if q > 1:
					print(s[:i] + '0' + s[i + 1:])
					break
	elif a > 0:
		print('A0' + s[2:])
	elif b > 0:
		print('a0' + s[2:])
	elif c > 0:
		print('Aa' + s[2:])


t = int(input())
for l in range(t):
	s1 = '0123456789'
	count1 = 0
	count2 = 0
	count3 = 0
	s = str(input())
	for i in s:
		if 65 <= ord(i) <= 90:
			count1 += 1
		elif 97 <= ord(i) <= 122:
			count2 += 1
		elif i in s1:
			count3 += 1
	if count1 > 0 and count2 > 0 and (count3 > 0):
		print(s)
	elif count1 == len(s) or count2 == len(s) or count3 == len(s):
		if count1 == len(s):
			print('a1' + s[2:])
		elif count2 == len(s):
			print('A1' + s[2:])
		else:
			print('Aa' + s[2:])
	elif count1 == 0 or count2 == 0 or count3 == 0:
		if count1 == 0:
			if count2 > 1:
				for i in range(len(s)):
					if 97 <= ord(s[i]) <= 122:
						s = s[:i] + 'A' + s[i + 1:]
						break
			else:
				for i in range(len(s)):
					if s[i] in s1:
						s = s[:i] + 'A' + s[i + 1:]
						break
		elif count2 == 0:
			if count1 > 1:
				for i in range(len(s)):
					if 65 <= ord(s[i]) <= 90:
						s = s[:i] + 'a' + s[i + 1:]
						break
			else:
				for i in range(len(s)):
					if s[i] in s1:
						s = s[:i] + 'a' + s[i + 1:]
						break
		elif count1 > 1:
			for i in range(len(s)):
				if 65 <= ord(s[i]) <= 90:
					s = s[:i] + '1' + s[i + 1:]
					break
		else:
			for i in range(len(s)):
				if 97 <= ord(s[i]) <= 122:
					s = s[:i] + '1' + s[i + 1:]
					break
		print(s)


t = int(input())

def yes(s, p):
	k = False
	for i in s:
		if i in p:
			k = True
	return k

def ok(s):
	pp = 'POIUYTREWQASDFGHJKLMNBVCXZ'
	p = 'qwertyuioplkjhgfdsazxcvbnm'
	ppp = '1234567890'
	if yes(s, p) and yes(s, pp) and yes(s, ppp):
		return True
	return False

def abra(s):
	if ok(s):
		return s
	ss = '1' + s[1:]
	if ok(ss):
		return ss
	ss = 'A' + s[1:]
	if ok(ss):
		return ss
	ss = 'a' + s[1:]
	if ok(ss):
		return ss
	ss = s[:len(s) - 1] + '1'
	if ok(ss):
		return ss
	ss = s[:len(s) - 1] + 'A'
	if ok(ss):
		return ss
	ss = s[:len(s) - 1] + 'a'
	if ok(ss):
		return ss
	ss = '1a' + s[2:]
	if ok(ss):
		return ss
	ss = '1A' + s[2:]
	if ok(ss):
		return ss
	ss = 'Aa' + s[2:]
	return ss
for i in range(t):
	s = input()
	print(abra(s))


test_num = int(input())
for i in range(test_num):
	password = input()
	stuff = [0, 0, 0]
	for char in password:
		stuff[0] += 1 if char.islower() and char.isalpha() else 0
		stuff[1] += 1 if char.isupper() and char.isalpha() else 0
		stuff[2] += 1 if char.isdigit() else 0
	target = [entry == 0 for entry in stuff]
	replacable = [entry > 1 for entry in stuff]
	three_found = [entry > 2 for entry in stuff]
	if stuff.count(0) > 1:
		prev_pos = -1
		min_len = -1
		prev_type = -1
		for (i, char) in enumerate(password):
			if char.isdigit():
				type = 2
			elif char.isupper():
				type = 1
			else:
				type = 0
			if replacable[type] and (prev_type != type or three_found[type]):
				if prev_pos == -1:
					prev_pos = i
				else:
					min_len = i - prev_pos
					sol = (prev_pos, i)
					prev_pos = i
					prev_type = type
		for i in sol:
			if target[0]:
				password = password[:i] + 'l' + password[i + 1:]
				target[0] = False
			elif target[1]:
				password = password[:i] + 'L' + password[i + 1:]
				target[1] = False
			else:
				password = password[:i] + '1' + password[i + 1:]
				target[2] = False
		print(password)
	elif stuff.count(0) == 1:
		for (i, char) in enumerate(password):
			if char.isdigit():
				type = 2
			elif char.isupper():
				type = 1
			else:
				type = 0
			if replacable[type]:
				if target[0]:
					password = password[:i] + 'l' + password[i + 1:]
					target[0] = False
				elif target[1]:
					password = password[:i] + 'L' + password[i + 1:]
					target[1] = False
				else:
					password = password[:i] + '1' + password[i + 1:]
					target[2] = False
				break
		print(password)
	else:
		print(password)


gi = lambda : list(map(int, input().split()))
(n,) = gi()
alph = 'abcdefghijklmnopqrstuvwxyz'
dig = '1234567890'
Ualph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for k in range(n):
	s = input()
	u = l = d = False
	for e in s:
		if e in alph:
			l = True
		elif e in Ualph:
			u = True
		else:
			d = True
	le = len(s)
	if int(d) + int(u) + int(l) == 1:
		if s[0] in alph:
			s = 'A1' + s[2:]
		elif s[0] in Ualph:
			s = 'a1' + s[2:]
		else:
			s = 'Aa' + s[2:]
	else:
		u1 = l1 = d1 = False
		for j in range(le):
			if u1 and s[j] in Ualph:
				if not d:
					s = s[:j] + '1' + s[j + 1:]
				elif not l:
					s = s[:j] + 'a' + s[j + 1:]
				break
			elif l1 and s[j] in alph:
				if not d:
					s = s[:j] + '1' + s[j + 1:]
				elif not u:
					s = s[:j] + 'A' + s[j + 1:]
				break
			elif d1 and s[j] in dig:
				if not u:
					s = s[:j] + 'A' + s[j + 1:]
				elif not l:
					s = s[:j] + 'a' + s[j + 1:]
				break
			elif s[j] in alph:
				l1 = True
			elif s[j] in Ualph:
				u1 = True
			else:
				d1 = True
	print(s)


def ok(str):
	flagDigit = False
	flagUpper = False
	flagLower = False
	for x in str:
		flagDigit = flagDigit or x.isdigit()
		flagUpper = flagUpper or x.isupper()
		flagLower = flagLower or x.islower()
	return flagDigit and flagUpper and flagLower
for T in list(range(int(input()))):
	str = input()
	if ok(str):
		print(str)
		continue
	fnd = False
	strlen = len(str)
	for i in list(range(strlen)):
		str2 = list(str)
		str2[i] = '0'
		if ok(str2):
			fnd = True
			print(''.join(str2))
			break
		str2[i] = 'a'
		if ok(str2):
			fnd = True
			print(''.join(str2))
			break
		str2[i] = 'A'
		if ok(str2):
			fnd = True
			print(''.join(str2))
			break
	if fnd:
		continue
	str = list(str)
	if str[2].isupper():
		str[0] = '0'
		str[1] = 'a'
		print(''.join(str))
		continue
	if str[2].islower():
		str[0] = '0'
		str[1] = 'A'
		print(''.join(str))
		continue
	if str[2].isdigit():
		str[0] = 'A'
		str[1] = 'a'
		print(''.join(str))
		continue


T = int(input())
for _ in range(T):
	string = input()
	low = 0
	up = 0
	dig = 0
	flow = 0
	fup = 0
	fdig = 0
	for i in string:
		if i.islower() is True:
			low += 1
			if low == 1:
				flow = i
		elif i.isupper() is True:
			up += 1
			if up == 1:
				fup = i
		elif i.isdigit() is True:
			dig += 1
			if dig == 1:
				fdig = i
	if low * up * dig > 0:
		print(string)
	elif up * dig > 0:
		if dig == 1 and fdig == string[0]:
			print(string[0] + 'a' + string[2:])
		elif up == 1 and fup == string[0]:
			print(string[0] + 'a' + string[2:])
		else:
			print('a' + string[1:])
	elif up * low > 0:
		if low == 1 and flow == string[0]:
			print(string[0] + '1' + string[2:])
		elif up == 1 and fup == string[0]:
			print(string[0] + '1' + string[2:])
		else:
			print('1' + string[1:])
	elif dig * low > 0:
		if low == 1 and flow == string[0]:
			print(string[0] + 'A' + string[2:])
		elif dig == 1 and fdig == string[0]:
			print(string[0] + 'A' + string[2:])
		else:
			print('A' + string[1:])
	elif dig > 0:
		print('aA' + string[2:])
	elif up > 0:
		print('a1' + string[2:])
	else:
		print('A1' + string[2:])


test_cases = int(input())
for n in range(test_cases):
	init_pass = input()
	pass_ls = list(init_pass)
	n_caps = 0
	n_lows = 0
	n_nums = 0
	for i in range(len(pass_ls)):
		if pass_ls[i].islower():
			n_lows += 1
		elif pass_ls[i].isupper():
			n_caps += 1
		else:
			n_nums += 1
	if n_caps > 0 and n_lows > 0 and (n_nums > 0):
		print(init_pass)
	else:
		caps_needed = int(n_caps == 0)
		lows_needed = int(n_lows == 0)
		nums_needed = int(n_nums == 0)
		if caps_needed:
			if lows_needed:
				pass_ls[0] = 'A'
				pass_ls[1] = 'z'
			elif nums_needed:
				pass_ls[0] = 'A'
				pass_ls[1] = '7'
			elif n_lows > 1 and n_nums > 1:
				pass_ls[0] = 'A'
			elif n_lows == 1:
				idx_lows = [idx for (idx, x) in enumerate(pass_ls) if x.islower()]
				pass_ls[idx_lows[0] - 1] = 'A'
			elif n_nums == 1:
				idx_nums = [idx for (idx, x) in enumerate(pass_ls) if not x.islower() and (not x.isupper())]
				pass_ls[idx_nums[0] - 1] = 'A'
		elif nums_needed:
			if lows_needed:
				pass_ls[0] = '7'
				pass_ls[1] = 'z'
			elif n_lows > 1 and n_caps > 1:
				pass_ls[0] = '7'
			elif n_lows == 1:
				idx_lows = [idx for (idx, x) in enumerate(pass_ls) if x.islower()]
				pass_ls[idx_lows[0] - 1] = '7'
			elif n_caps == 1:
				idx_caps = [idx for (idx, x) in enumerate(pass_ls) if x.isupper()]
				pass_ls[idx_caps[0] - 1] = '7'
		elif n_nums > 1 and n_caps > 1:
			pass_ls[0] = 's'
		elif n_nums == 1:
			idx_nums = [idx for (idx, x) in enumerate(pass_ls) if not x.islower() and (not x.isupper())]
			pass_ls[idx_nums[0] - 1] = 's'
		elif n_caps == 1:
			idx_caps = [idx for (idx, x) in enumerate(pass_ls) if x.isupper()]
			pass_ls[idx_caps[0] - 1] = 's'
		print(''.join(pass_ls))


import string
from collections import Counter
t = int(input())

def ret_class(chr):
	if chr in string.ascii_lowercase:
		return 1
	if chr in string.ascii_uppercase:
		return 2
	if chr in string.digits:
		return 3
c = {1: 'a', 2: 'A', 3: '1'}
for _ in range(t):
	s = input()
	s_cls = [ret_class(ch) for ch in s]
	if len(set(s_cls)) == 3:
		print(s)
	elif len(set(s_cls)) == 1:
		to_fill = [1, 2, 3]
		to_fill.remove(set(s_cls).pop())
		print(c[to_fill[0]] + c[to_fill[1]] + s[2:])
	elif len(set(s_cls)) == 2:
		max_cls = max(Counter(s_cls).items(), key=lambda x: x[1])[0]
		idx = s_cls.index(max_cls)
		clss = {1, 2, 3} - set(s_cls)
		print(s[:idx] + str(c[clss.pop()]) + s[idx + 1:])


import sys
import string

def getSubstring(lower, upper, digit):
	ret = ''
	if lower is not True:
		ret += 'a'
	if upper is not True:
		ret += 'A'
	if digit is not True:
		ret += '0'
	return ret

def checkPassword(s):
	(lower, upper, digit) = ([False, 0], [False, 0], [False, 0])
	for c in s:
		if c in string.ascii_lowercase:
			lower[0] = True
			lower[1] += 1
		elif c in string.ascii_uppercase:
			upper[0] = True
			upper[1] += 1
		else:
			digit[0] = True
			digit[1] += 1
	return (lower, upper, digit)

def solve(s):
	(lower, upper, digit) = checkPassword(s)
	ss = getSubstring(lower[0], upper[0], digit[0])
	if len(ss) == 0:
		return s
	if lower[1] > 1:
		kls = string.ascii_lowercase
	elif upper[1] > 1:
		kls = string.ascii_uppercase
	elif digit[1] > 1:
		kls = string.digits
	if len(ss) == 1:
		if lower[1] > 1:
			kls = string.ascii_lowercase
		elif upper[1] > 1:
			kls = string.ascii_uppercase
		elif digit[1] > 1:
			kls = string.digits
		for (i, c) in enumerate(s):
			if c in kls:
				return s[:i] + ss + s[i + 1:]
	if len(ss) == 2:
		for i in range(len(s) - 1):
			if s[i] in kls and s[i + 1] in kls:
				return s[:i] + ss + s[i + 2:]

def main():
	_ = sys.stdin.readline()
	for s in sys.stdin:
		print(solve(s.strip()))
main()


import string
tst = int(input())
for te in range(tst):
	s = input()
	t = [0, 0, 0]
	for c in s:
		if c in string.ascii_lowercase:
			t[0] += 1
		elif c in string.ascii_uppercase:
			t[1] += 1
		else:
			t[2] += 1
	if t[0] > 0 and t[1] > 0 and (t[2] > 0):
		print(s)
		continue
	s = list(s)
	if t[0] > 0 and t[1] > 0:
		if t[0] > 1:
			for i in range(len(s)):
				if s[i] in string.ascii_lowercase:
					s[i] = '0'
					print(''.join(s))
					break
			continue
		else:
			for i in range(len(s)):
				if s[i] in string.ascii_uppercase:
					s[i] = '0'
					print(''.join(s))
					break
			continue
	if t[0] > 0 and t[2] > 0:
		if t[0] > 1:
			for i in range(len(s)):
				if s[i] in string.ascii_lowercase:
					s[i] = 'A'
					print(''.join(s))
					break
			continue
		else:
			for i in range(len(s)):
				if s[i] in string.digits:
					s[i] = 'A'
					print(''.join(s))
					break
			continue
	if t[1] > 0 and t[2] > 0:
		if t[1] > 1:
			for i in range(len(s)):
				if s[i] in string.ascii_uppercase:
					s[i] = 'a'
					print(''.join(s))
					break
			continue
		else:
			for i in range(len(s)):
				if s[i] in string.digits:
					s[i] = 'a'
					print(''.join(s))
					break
			continue
	if t[0] > 1:
		for i in range(len(s)):
			if s[i] in string.ascii_lowercase:
				if t[1] == 0:
					s[i] = 'A'
					t[1] = 1
				elif t[2] == 0:
					s[i] = '0'
					t[2] = 1
					print(''.join(s))
					break
	elif t[1] > 1:
		for i in range(len(s)):
			if s[i] in string.ascii_uppercase:
				if t[0] == 0:
					s[i] = 'a'
					t[0] = 1
				elif t[2] == 0:
					s[i] = '0'
					t[2] = 1
					print(''.join(s))
					break
	elif t[2] > 1:
		for i in range(len(s)):
			if s[i] in string.digits:
				if t[0] == 0:
					s[i] = 'a'
					t[0] = 1
				elif t[1] == 0:
					s[i] = 'A'
					t[1] = 1
					print(''.join(s))
					break


T = int(input())
for i in range(T):
	s = str(input())
	u = s[0:len(s):1]
	k = [[], [], []]
	for i in range(len(s)):
		a = s[i]
		try:
			int(a)
			k[0].append(i)
		except:
			if a == a.lower():
				k[1].append(i)
			else:
				k[2].append(i)
	s = u
	if len(k[0]) == 0:
		if len(k[1]) > 1:
			a = k[1][1]
			s = s[0:a:1] + '1' + s[a + 1:len(s):1]
		elif len(k[2]) > 1:
			a = k[2][1]
			s = s[0:a:1] + '1' + s[a + 1:len(s):1]
	u = s[0:len(s):1]
	k = [[], [], []]
	for i in range(len(s)):
		a = s[i]
		try:
			int(a)
			k[0].append(i)
		except:
			if a == a.lower():
				k[1].append(i)
			else:
				k[2].append(i)
	s = u
	if len(k[1]) == 0:
		if len(k[0]) > 1:
			a = k[0][1]
			s = s[0:a:1] + 'a' + s[a + 1:len(s):1]
		elif len(k[2]) > 1:
			a = k[2][1]
			s = s[0:a:1] + 'a' + s[a + 1:len(s):1]
	u = s[0:len(s):1]
	k = [[], [], []]
	for i in range(len(s)):
		a = s[i]
		try:
			int(a)
			k[0].append(i)
		except:
			if a == a.lower():
				k[1].append(i)
			else:
				k[2].append(i)
	s = u
	if len(k[2]) == 0:
		if len(k[1]) > 1:
			a = k[1][1]
			s = s[0:a:1] + 'A' + s[a + 1:len(s):1]
		elif len(k[0]) > 1:
			a = k[0][1]
			s = s[0:a:1] + 'A' + s[a + 1:len(s):1]
	print(s)


t = int(input())
for i in range(t):
	s = input()
	a = [x for x in s if 65 <= ord(x) <= 90]
	b = [x for x in s if 96 <= ord(x) <= 122]
	c = [x for x in s if 48 <= ord(x) <= 57]
	l = [len(a), len(b), len(c)]
	j = [x for x in l if x == 0]
	k = len(j)
	if k == 0:
		print(s)
		continue
	elif k == 2:
		o = ord(s[0])
		if 65 <= o <= 90:
			s = 'a9' + s[2:]
		if 96 <= o <= 122:
			s = 'A9' + s[2:]
		if 48 <= o <= 57:
			s = 'aA' + s[2:]
	else:
		if len(a) == 0:
			if len(b) > 1:
				e = s.index(b[0])
				s = s[:e] + 'A' + s[e + 1:]
			else:
				e = s.index(c[0])
				s = s[:e] + 'A' + s[e + 1:]
		if len(b) == 0:
			if len(a) > 1:
				e = s.index(a[0])
				s = s[:e] + 'a' + s[e + 1:]
			else:
				e = s.index(c[0])
				s = s[:e] + 'a' + s[e + 1:]
		if len(c) == 0:
			if len(a) > 1:
				e = s.index(a[0])
				s = s[:e] + '1' + s[e + 1:]
			else:
				e = s.index(b[0])
				s = s[:e] + '1' + s[e + 1:]
	print(s)


T = int(input())
for i in range(T):
	s = list(input())
	(a, b, c) = (0, 0, 0)
	(fa, fb, fc) = (-1, -1, -1)
	for j in range(len(s)):
		if 'a' <= s[j] <= 'z':
			a += 1
			fa = j
		if 'A' <= s[j] <= 'Z':
			b += 1
			fb = j
		if '0' <= s[j] <= '9':
			c += 1
			fc = j
	if a > 0 and b > 0 and (c > 0):
		s
	elif a > 0 and b > 0:
		for q in range(len(s)):
			if q != fa and q != fb:
				s[q] = '0'
				break
	elif a > 0 and c > 0:
		for q in range(len(s)):
			if q != fa and q != fc:
				s[q] = 'A'
				break
	elif b > 0 and c > 0:
		for q in range(len(s)):
			if q != fb and q != fc:
				s[q] = 'a'
				break
	elif fa > 0:
		if fa >= 2:
			s[0] = 'A'
			s[1] = '0'
		else:
			s[fa + 1] = 'A'
			s[fa + 2] = '0'
	elif fb > 0:
		if fb >= 2:
			s[0] = 'a'
			s[1] = '0'
		else:
			s[fa + 1] = 'a'
			s[fa + 2] = '0'
	elif fc > 0:
		if fc >= 2:
			s[0] = 'a'
			s[1] = 'A'
		else:
			s[fa + 1] = 'a'
			s[fa + 2] = 'A'
	print(''.join(s))


n = int(input())
for i in range(0, n):
	a = input()
	ch = 0
	b = 0
	m = 0
	j = 0
	for i in a:
		if ord(i) >= ord('0') and ord(i) <= ord('9'):
			ch += 1
			ch_ = j
		elif ord(i) >= ord('a') and ord(i) <= ord('z'):
			m += 1
			m_ = j
		elif ord(i) >= ord('A') and ord(i) <= ord('Z'):
			b += 1
			b_ = j
		j += 1
	if ch > 0 and b > 0 and (m > 0):
		print(a)
	elif ch > 0 and b > 0 or (ch > 0 and m > 0) or (b > 0 and m > 0):
		if ch == 0:
			if b > m:
				print(a[0:b_] + '1' + a[b_ + 1:])
			else:
				print(a[0:m_] + '1' + a[m_ + 1:])
		elif b == 0:
			if ch > m:
				print(a[0:ch_] + 'A' + a[ch_ + 1:])
			else:
				print(a[0:m_] + 'A' + a[m_ + 1:])
		elif m == 0:
			if ch > b:
				print(a[0:ch_] + 'a' + a[ch_ + 1:])
			else:
				print(a[0:b_] + 'a' + a[b_ + 1:])
	elif ch > 0:
		print('Aa' + a[2:])
	elif b > 0:
		print('a1' + a[2:])
	elif m > 0:
		print('A1' + a[2:])


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	s = scan_string()
	check = [0, 0, 0]
	for x in s:
		if x.isalpha() and x in alphs:
			check[0] += 1
		elif x.isalpha() and x in alphs.upper():
			check[1] += 1
		else:
			check[2] += 1
	if check[0] > 0 and check[1] > 0 and (check[2] > 0):
		print(s)
		return
	rep = ''
	if check[0] == 0:
		rep = rep + 'a'
	if check[1] == 0:
		rep = rep + 'A'
	if check[2] == 0:
		rep = rep + '1'
	ans1 = rep + s[len(rep):]
	ans2 = s[:-len(rep)] + rep
	(flag1, flag2, flag3) = (0, 0, 0)
	for x in ans1:
		if x.isalpha() and x in alphs:
			flag1 = 1
		elif x.isalpha() and x in alphs.upper():
			flag2 = 1
		else:
			flag3 = 1
	if flag1 == 1 and flag2 == 1 and (flag3 == 1):
		print(ans1)
	else:
		print(ans2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	b = input()
	c = []
	d = []
	e = []
	for j in range(len(b)):
		if ord(b[j]) in range(65, 91):
			c.append(j)
		elif ord(b[j]) in range(97, 123):
			d.append(j)
		else:
			e.append(j)
	x = []
	for j in b:
		x.append(j)
	if len(c) == 0 and len(d) == 0:
		x[0] = 'A'
		x[1] = 'a'
	elif len(c) == 0 and len(e) == 0:
		x[0] = 'A'
		x[1] = '1'
	elif len(d) == 0 and len(e) == 0:
		x[0] = 'a'
		x[1] = '1'
	elif len(d) == 0:
		if len(c) > 1 and len(e) > 1:
			x[0] = 'a'
		elif len(c) == 1 and len(e) > 1:
			x[e[0]] = 'a'
		elif len(e) == 1 and len(c) > 1:
			x[c[0]] = 'a'
	elif len(e) == 0:
		if len(d) > 1 and len(c) > 1:
			x[0] = '1'
		elif len(d) == 1 and len(c) > 1:
			x[c[0]] = '1'
		elif len(c) == 1 and len(d) > 1:
			x[d[0]] = '1'
	elif len(c) == 0:
		if len(d) > 1 and len(e) > 1:
			x[0] = 'A'
		elif len(d) == 1 and len(e) > 1:
			x[e[0]] = 'A'
		elif len(e) == 1 and len(d) > 1:
			x[d[0]] = 'A'
	print(''.join(x))


import math
from collections import deque

def main():
	a = set(list('abcdefghijklmnopqrstuvwxyz'))
	A = set(list('ABCDEFGHIJKLMNOPQRSTUVWXYZ'))
	n = int(input())
	for i in range(n):
		s = list(input())
		cntA = 0
		cnta = 0
		cnt1 = 0
		ai = -1
		Ai = -1
		i1 = -1
		for i in range(len(s)):
			c = s[i]
			if c in a:
				ai = i
				cnta += 1
			elif c in A:
				Ai = i
				cntA += 1
			else:
				i1 = i
				cnt1 += 1
		if cntA == 0 and cnta == 0:
			s[0] = 'A'
			s[1] = 'a'
		elif cntA == 0 and cnt1 == 0:
			s[0] = 'A'
			s[1] = '1'
		elif cnta == 0 and cnt1 == 0:
			s[0] = 'a'
			s[1] = '1'
		elif cntA == 0:
			if cnta > cnt1:
				cnta -= 1
				cntA += 1
				s[ai] = 'A'
			else:
				cnt1 -= 1
				cntA += 1
				s[i1] = 'A'
		elif cnta == 0:
			if cntA > cnt1:
				cntA -= 1
				cnta += 1
				s[Ai] = 'a'
			else:
				cnt1 -= 1
				cnta += 1
				s[i1] = 'a'
		elif cnt1 == 0:
			if cnta > cntA:
				cnta -= 1
				cnt1 += 1
				s[ai] = '1'
			else:
				cntA -= 1
				cnt1 += 1
				s[Ai] = '1'
		print(''.join(s))
	return 0
main()


t = int(input())
for i in range(t):
	s = input()
	a = -1
	B = -1
	c = -1
	for j in range(len(s)):
		if a == -1 and 'a' <= s[j] <= 'z':
			a = j
		if B == -1 and 'A' <= s[j] <= 'Z':
			B = j
		if c == -1 and '0' <= s[j] <= '9':
			c = j
		if a != -1 and B != -1 and (c != -1):
			break
	if a != -1 and B != -1 and (c != -1):
		print(s)
	elif a != -1 and B != -1:
		c = 0 if a != 0 and B != 0 else 1 if a != 1 and B != 1 else 2
		s = s[:c] + '0' + s[c + 1:]
		print(s)
	elif a != -1 and c != -1:
		B = 0 if a != 0 and c != 0 else 1 if a != 1 and c != 1 else 2
		s = s[:B] + 'A' + s[B + 1:]
		print(s)
	elif B != -1 and c != -1:
		a = 0 if c != 0 and B != 0 else 1 if c != 1 and B != 1 else 2
		s = s[:a] + 'a' + s[a + 1:]
		print(s)
	elif a != -1:
		r = 0 if a > 1 else 1 if a == 0 else 2
		if r == 2:
			s = '1' + s[1] + 'A' + s[3:]
		else:
			s = s[:r] + '1A' + s[r + 2:]
		print(s)
	elif B != -1:
		r = 0 if B > 1 else 1 if B == 0 else 2
		if r == 2:
			s = '1' + s[1] + 'a' + s[3:]
		else:
			s = s[:r] + '1a' + s[r + 2:]
		print(s)
	else:
		r = 0 if c > 1 else 1 if c == 0 else 2
		if r == 2:
			s = 'A' + s[1] + 'a' + s[3:]
		else:
			s = s[:r] + 'aA' + s[r + 2:]
		print(s)


for _ in range(int(input())):
	d = input()
	x = len(d)
	l = []
	for i in range(x):
		l.append(d[i])
	countI = 0
	countU = 0
	countL = 0
	for i in d:
		if i.isdigit():
			countI += 1
		elif i.islower():
			countL += 1
		elif i.isupper():
			countU += 1
	s = ''
	if countI == 0:
		s = s + '7'
	if countL == 0:
		s = s + 'a'
	if countU == 0:
		s = s + 'A'
	if len(s) == 2:
		d = d[:len(d) - 2] + s
		print(d)
	elif len(s) == 1:
		g = ''
		for i in range(x):
			if l[len(d) - 1 - i].isdigit():
				if countI > 1:
					l[len(d) - 1 - i] = s
					break
			elif l[len(d) - 1 - i].islower():
				if countL > 1:
					l[len(d) - 1 - i] = s
					break
			elif l[len(d) - 1 - i].isupper():
				if countU > 1:
					l[len(d) - 1 - i] = s
					break
		for i in range(x):
			g = g + l[i]
		print(g)
	else:
		print(d)


def check_pass(password):
	upper = False
	num = False
	lower = False
	for ch in password:
		if ord(ch) >= 97 and ord(ch) <= 122:
			lower = True
		elif ord(ch) >= 65 and ord(ch) <= 90:
			upper = True
		elif int(ch) >= 0 and int(ch) <= 9:
			num = True
	return {'_acceptable': upper & lower & num, 'upper': upper, 'lower': lower, 'num': num}

def change_char(password, index, conditions):
	new_password = list(password)
	if not conditions['upper']:
		new_password[index] = 'A'
	elif not conditions['lower']:
		new_password[index] = 'a'
	elif not conditions['num']:
		new_password[index] = '4'
	new_password = ''.join(new_password)
	obj = check_pass(new_password)
	if not obj['_acceptable']:
		if conditions['upper']:
			if not obj['upper']:
				return password
		if conditions['lower']:
			if not obj['lower']:
				return password
		if conditions['num']:
			if not obj['num']:
				return password
	return new_password
n = int(input())
passwords = []
for i in range(n):
	passwords.append(input())
for password in passwords:
	if not check_pass(password)['_acceptable']:
		index = 0
		temp = password
		while not check_pass(password)['_acceptable']:
			password = change_char(password, index, check_pass(password))
			index += 1
	print(password)


def passwordify(s):
	d = {'lower': 'a', 'upper': 'A', 'digit': '0'}
	h = {'lower': [], 'upper': [], 'digit': []}
	for (i, c) in enumerate(s):
		if c.isalpha():
			if c.islower():
				h['lower'].append((i, c))
			else:
				h['upper'].append((i, c))
		else:
			h['digit'].append((i, c))
	missing = []
	ok = []
	for k in h:
		if not h[k]:
			missing.append(k)
		else:
			ok.append(k)
	if len(missing) == 0:
		return s
	ok = sorted(ok, key=lambda x: len(h[x]), reverse=True)
	if len(missing) == 1:
		t = h[ok[0]].pop()
		h[missing[0]].append((t[0], d[missing[0]]))
	else:
		(t1, t2) = (h[ok[0]].pop(), h[ok[0]].pop())
		h[missing[0]].append((t1[0], d[missing[0]]))
		h[missing[1]].append((t2[0], d[missing[1]]))
	return ''.join((t[1] for t in sorted(h['lower'] + h['upper'] + h['digit'])))

def main():
	t = int(input())
	for i in range(t):
		s = input()
		print(passwordify(s))
main()


def solve():
	s = input()
	ct = [0] * 3
	for i in s:
		ct[0] += i.islower()
		ct[1] += i.isupper()
		ct[2] += i.isdigit()
	t = list(s)
	for (ii, i) in enumerate(s):
		if ct[0] == 0:
			if i.isupper() and ct[1] > 1:
				t[ii] = i.lower()
				ct[1] -= 1
				ct[0] += 1
			elif i.isdigit() and ct[2] > 1:
				t[ii] = 'a'
				ct[2] -= 1
				ct[0] += 1
		elif ct[1] == 0:
			if i.islower() and ct[0] > 1:
				t[ii] = i.upper()
				ct[0] -= 1
				ct[1] += 1
			elif i.isdigit() and ct[2] > 1:
				t[ii] = 'A'
				ct[2] -= 1
				ct[1] += 1
		elif ct[2] == 0:
			if i.isupper() and ct[1] > 1:
				t[ii] = '0'
				ct[1] -= 1
				ct[2] += 1
			elif i.islower() and ct[0] > 1:
				t[ii] = '0'
				ct[0] -= 1
				ct[2] += 1
		else:
			break
	print(''.join(t))

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


T = int(input())
while T > 0:
	s = input()
	count1 = 0
	count2 = 0
	count3 = 0
	nums = []
	caps = []
	sms = []
	for a in s:
		if a.isupper() == True:
			count1 += 1
			caps.append(a)
		elif a.islower() == True:
			count2 += 1
			sms.append(a)
		elif a.isdigit() == True:
			count3 += 1
			nums.append(a)
	s = list(s)
	if count3 >= 1 and count2 >= 1 and (count1 >= 1):
		print(''.join(s))
	elif count1 >= 1 and count2 >= 1:
		if count2 >= 2:
			s[s.index(sms[0])] = '1'
		else:
			s[s.index(caps[0])] = '1'
		print(''.join(s))
	elif count2 >= 1 and count3 >= 1:
		if count2 >= 2:
			s[s.index(sms[0])] = 'A'
		else:
			s[s.index(nums[0])] = 'A'
		print(''.join(s))
	elif count1 >= 1 and count3 >= 1:
		if count1 >= 2:
			s[s.index(caps[0])] = 'a'
		else:
			s[s.index(nums[0])] = 'a'
		print(''.join(s))
	elif count1 >= 1:
		s[0] = 'a'
		s[1] = '1'
		print(''.join(s))
	elif count2 >= 1:
		s[0] = 'A'
		s[1] = '1'
		print(''.join(s))
	elif count3 >= 1:
		s[0] = 'a'
		s[1] = 'A'
		print(''.join(s))
	T -= 1


t = int(input())
for i in range(t):
	s = input()
	lower = 0
	upper = 0
	digit = 0
	for letter in s:
		if ord(letter) >= 65 and ord(letter) <= 90:
			upper += 1
		elif ord(letter) >= 97 and ord(letter) <= 122:
			lower += 1
		elif ord(letter) >= 48 and ord(letter) <= 57:
			digit += 1
	s = list(s)
	if digit == 0 and upper == 0:
		s[0] = '1'
		s[1] = 'A'
	elif digit == 0 and lower == 0:
		s[0] = '1'
		s[1] = 'a'
	elif upper == 0 and lower == 0:
		s[0] = 'A'
		s[1] = 'a'
	elif digit == 0:
		if lower > 1:
			for i in range(len(s)):
				if ord(s[i]) >= 97 and ord(s[i]) <= 122:
					s[i] = '1'
					break
		else:
			for i in range(len(s)):
				if ord(s[i]) >= 65 and ord(s[i]) <= 90:
					s[i] = '1'
					break
	elif upper == 0:
		if lower > 1:
			for i in range(len(s)):
				if ord(s[i]) >= 97 and ord(s[i]) <= 122:
					s[i] = 'A'
					break
		else:
			for i in range(len(s)):
				if ord(s[i]) >= 48 and ord(s[i]) <= 57:
					s[i] = 'A'
					break
	elif lower == 0:
		if upper > 1:
			for i in range(len(s)):
				if ord(s[i]) >= 65 and ord(s[i]) <= 90:
					s[i] = 'a'
					break
		else:
			for i in range(len(s)):
				if ord(s[i]) >= 48 and ord(s[i]) <= 57:
					s[i] = 'a'
					break
	out = ''
	for i in range(len(s)):
		out += s[i]
	print(out)


t = int(input())
for _ in range(t):
	s = str(input())
	l = []
	u = []
	d = []
	for (i, c) in enumerate(s):
		if c.islower():
			l.append(i)
		elif c.isupper():
			u.append(i)
		else:
			d.append(i)
	s = list(s)
	if l and u and d:
		pass
	elif not l and u and d:
		if len(u) > len(d):
			s[u[0]] = 'a'
		else:
			s[d[0]] = 'a'
	elif l and (not u) and d:
		if len(l) > len(d):
			s[l[0]] = 'A'
		else:
			s[d[0]] = 'A'
	elif l and u and (not d):
		if len(l) > len(u):
			s[l[0]] = '1'
		else:
			s[u[0]] = '1'
	elif l and (not u) and (not d):
		s[l[0]] = 'A'
		s[l[1]] = '1'
	elif not l and u and (not d):
		s[u[0]] = 'a'
		s[u[1]] = '1'
	elif not l and (not u) and d:
		s[d[0]] = 'a'
		s[d[1]] = 'A'
	print(''.join(s))


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for y in range(t):
	s = list(input())
	a = []
	b = []
	c = []
	n = len(s)
	for i in range(n):
		if '0' <= s[i] <= '9':
			a.append(i)
		elif s[i].islower() == True:
			b.append(i)
		else:
			c.append(i)
	if len(a) == 0:
		if len(b) > 1:
			s[b[0]] = '1'
		else:
			s[c[0]] = '1'
	if len(b) == 0:
		if len(a) > 1:
			s[a[0]] = 'a'
		else:
			s[c[1]] = 'a'
	if len(c) == 0:
		if len(b) > 1:
			s[b[1]] = 'A'
		else:
			s[a[1]] = 'A'
	print(''.join(s))


for _ in [0] * int(input()):
	s = list(input())
	a = '0Aa0A'
	l = [[], [], []]
	for (i, c) in enumerate(s):
		l[(c > '9') + (c > 'Z')] += [i]
	for (m, x) in enumerate(l):
		if x:
			i = m
		else:
			j = m
		if len(x) > 1:
			k = m
	n = sum((bool(x) for x in l))
	if n == 1:
		s[:2] = a[i + 1:i + 3]
	if n == 2:
		s[l[k][0]] = a[j]
	print(''.join(s))


TC = int(input())
subs = ['aA', 'a0', 'A0', '0Aa']
for T in range(TC):
	s = list(input())
	f = [[] for i in range(3)]
	for (i, c) in enumerate(s):
		if c.isdigit():
			f[0].append(i)
		if c.isupper():
			f[1].append(i)
		if c.islower():
			f[2].append(i)
	k = sum((bool(len(x)) for x in f))
	if k == 3:
		pass
	elif k == 2:
		i = f.index([])
		j = f[(i + 1) % 3][0] if len(f[(i + 1) % 3]) > 1 else f[(i + 2) % 3][0]
		s[j] = subs[-1][i]
	elif k == 1:
		i = list(filter(lambda x: x[0], zip(f, range(3))))[0][1]
		s = list(subs[i]) + s[2:]
	print(''.join(s))


import sys
import re
s = int(input())
arr = []
for i in range(s):
	lo = []
	up = []
	di = []
	string = str(sys.stdin.readline().rstrip())
	list1 = list(string)
	for i in range(len(string)):
		if string[i].islower():
			lo.append(i)
		elif string[i].isupper():
			up.append(i)
		elif string[i].isdigit():
			di.append(i)
	if not lo:
		if len(up) > 1:
			list1[up[len(up) - 1]] = string[up[len(up) - 1]].lower()
			lo.append(up[len(up) - 1])
			up.pop()
		elif len(di) > 1:
			list1[di[len(di) - 1]] = 'a'
			lo.append(di[len(di) - 1])
			di.pop()
	if not up:
		if len(lo) > 1:
			list1[lo[len(lo) - 1]] = string[lo[len(lo) - 1]].upper()
			up.append(lo[len(lo) - 1])
			lo.pop()
		elif len(di) > 1:
			list1[di[len(di) - 1]] = 'A'
			up.append(di[len(di) - 1])
			di.pop()
	if not di:
		if len(up) > 1:
			list1[up[len(up) - 1]] = '4'
			di.append(up[len(up) - 1])
			up.pop()
		elif len(lo) > 1:
			list1[lo[len(lo) - 1]] = '4'
			di.append(lo[len(lo) - 1])
			lo.pop()
	string = ''.join(list1)
	arr.append(string)
for i in range(s):
	print(arr[i])


def func(x, y, s, c):
	low = min(x, y)
	high = max(x, y)
	x = high - low
	if x == 1 and low - 1 >= 0:
		s = s[0:low - 1] + c + s[low:]
	elif x == 1 and high + 1 < len(s):
		s = s[0:high] + c + s[high + 1:]
	else:
		s = s[0:x] + c + s[x + 1:]
	return s

def solve(arr, n):
	ans = []
	upper = False
	lower = False
	digit = False
	for i in range(n):
		s = arr[i]
		length = len(s)
		lower = -1
		upper = -1
		digit = -1
		for j in range(length):
			if s[j].islower():
				lower = j
			elif s[j].isupper():
				upper = j
			elif not s[j].isalpha():
				digit = j
		if lower > -1 and upper > -1 and (digit > -1):
			ans.append(s)
		else:
			if upper > -1 and digit > -1:
				s = func(upper, digit, s, 'a')
			elif upper > -1 and lower > -1:
				s = func(upper, lower, s, '1')
			elif lower > -1 and digit > -1:
				s = func(lower, digit, s, 'A')
			elif lower > -1:
				s = '1A' + s[2:]
			elif upper > -1:
				s = '1a' + s[2:]
			else:
				s = 'aB' + s[2:]
			ans.append(s)
	return ans

def main():
	n = int(input())
	arr = []
	for i in range(n):
		arr.append(input())
	ans = solve(arr, n)
	for i in range(n):
		print(ans[i])
main()


n = int(input())
for i in range(n):
	x = input()
	u = 0
	l = 0
	d = 0
	for i in x:
		if ord(i) <= 122 and ord(i) >= 97:
			l = l + 1
		elif ord(i) <= 90 and ord(i) >= 65:
			u = u + 1
		elif ord(i) <= 57 and ord(i) >= 48:
			d = d + 1
	if u != 0 and l != 0 and (d != 0):
		print(x)
	elif u == 0 and d == 0:
		y = 'A' + '1' + x[2:]
		print(y)
	elif u == 0 and l == 0:
		y = 'A' + 'a' + x[2:]
		print(y)
	elif l == 0 and d == 0:
		y = 'a' + '1' + x[2:]
		print(y)
	elif u == 0:
		if l > d:
			for i in x:
				if ord(i) <= 122 and ord(i) >= 97:
					c = x.index(i)
					break
			y = x[0:c] + 'A' + x[c + 1:]
		else:
			for i in x:
				if ord(i) <= 57 and ord(i) >= 48:
					c = x.index(i)
					break
			y = x[0:c] + 'A' + x[c + 1:]
		print(y)
	elif l == 0:
		if u > d:
			for i in x:
				if ord(i) <= 90 and ord(i) >= 65:
					c = x.index(i)
					break
			y = x[0:c] + 'a' + x[c + 1:]
		else:
			for i in x:
				if ord(i) <= 57 and ord(i) >= 48:
					c = x.index(i)
					break
			y = x[0:c] + 'a' + x[c + 1:]
		print(y)
	elif d == 0:
		if l > u:
			for i in x:
				if ord(i) <= 122 and ord(i) >= 97:
					c = x.index(i)
					break
			y = x[0:c] + '1' + x[c + 1:]
		else:
			for i in x:
				if ord(i) <= 90 and ord(i) >= 65:
					c = x.index(i)
					break
			y = x[0:c] + '1' + x[c + 1:]
		print(y)


def strong(password):
	lower = False
	upper = False
	digit = False
	for c in password:
		if c.islower():
			lower = True
		if c.isupper():
			upper = True
		if c.isdigit():
			digit = True
	return lower and upper and digit
T = int(input())
passwords = ['' for _ in range(T)]
for t in range(T):
	passwords[t] = list(input())
newpasswords = ['' for _ in range(T)]
for (i, password) in enumerate(passwords):
	if strong(password):
		newpasswords[i] = password
	else:
		isOk = False
		for s in ['a', 'A', '1']:
			if isOk:
				break
			for j in range(len(password)):
				trypassword = password.copy()
				trypassword[j] = s
				if strong(trypassword):
					newpasswords[i] = trypassword
					isOk = True
					break
		for s in ['aA', 'a1', 'A1']:
			if isOk:
				break
			for j in range(len(password) - 1):
				trypassword = password.copy()
				trypassword[j:j + 2] = s
				if strong(trypassword):
					newpasswords[i] = trypassword
					isOk = True
					break
for password in newpasswords:
	print(''.join(password))


t = int(input())
for i in range(t):
	p = input()
	s = []
	for charr in p:
		s.append(charr)
	lowerc = 0
	upperc = 0
	dig = 0
	lns = len(s)
	for charr in s:
		if charr.isupper():
			upperc += 1
		elif charr.islower():
			lowerc += 1
		elif charr.isdigit():
			dig += 1
	if dig > 0 and lowerc > 0 and (upperc > 0):
		pass
	elif dig > 1:
		if lowerc > 0:
			for i in range(lns):
				if s[i].isdigit():
					s[i] = 'A'
					break
		elif upperc > 0:
			for i in range(lns):
				if s[i].isdigit():
					s[i] = 'a'
					break
		else:
			s[0] = 'A'
			s[1] = 'a'
	elif upperc > 1:
		if lowerc > 0:
			for i in range(lns):
				if s[i].isupper():
					s[i] = '1'
					break
		elif dig > 0:
			for i in range(lns):
				if s[i].isupper():
					s[i] = 'a'
					break
		else:
			s[0] = '1'
			s[1] = 'a'
	elif lowerc > 1:
		if upperc > 0:
			for i in range(lns):
				if s[i].islower():
					s[i] = '1'
					break
		elif dig > 0:
			for i in range(lns):
				if s[i].islower():
					s[i] = 'A'
					break
		else:
			s[0] = '1'
			s[1] = 'A'
	ans = ''
	for djjs in s:
		ans += djjs
	print(ans)


import re
p = ('[a-z]', '[A-Z]', '[0-9]')
for _ in [0] * int(input()):
	s = input()
	for x in p:
		for y in p:
			if not re.search(f'{x}', s):
				s = re.sub(f'({y})(.*{y})', f'{x[1]}\\2', s)
	print(s)


for _ in range(int(input())):
	s = input()
	(digit, small, capital) = ([], [], [])
	for i in range(len(s)):
		if s[i] in '1234567890':
			digit.append(i)
		elif s[i] in 'abcdefghijklmnopqrstuvwxyz':
			small.append(i)
		else:
			capital.append(i)
	replace = ''
	if not capital:
		replace += 'A'
	if not small:
		replace += 'a'
	if not digit:
		replace += '1'
	if replace == '':
		print(s)
	else:
		l = len(replace)
		start = 0
		while True:
			if len(digit) == 1 and start <= digit[0] < start + l:
				start += 1
			if len(small) == 1 and start <= small[0] < start + l:
				start += 1
			if len(capital) == 1 and start <= capital[0] < start + l:
				start += 1
			else:
				break
		print(s[:start] + replace + s[start + l:])


while True:
	try:

		def check(v):
			nei = []
			for i in range(3):
				if v[i][0] == False:
					nei.append(v[i][1])
			return nei

		def solution():
			s1 = input()
			s = list(s1)
			visit = [[False, '0'], [False, 'A'], [False, 'a']]
			sLatn = 0
			cLatn = 0
			num = 0
			for i in range(len(s)):
				c = s[i]
				c = ord(c)
				if c >= 97 and c <= 122:
					sLatn += 1
					visit[2][0] = True
				elif c >= 65 and c <= 90:
					cLatn += 1
					visit[1][0] = True
				else:
					num += 1
					visit[0][0] = True
			has = check(visit)
			if len(has) == 0:
				print(s1)
				return
			ind = 0
			for i in range(len(s1)):
				c = s[i]
				c = ord(c)
				if c >= 97 and c <= 122 and (sLatn > 1):
					sLatn -= 1
					s[i] = has[ind]
					ind += 1
					if ind == len(has):
						break
				elif c >= 65 and c <= 90 and (cLatn > 1):
					cLatn -= 1
					s[i] = has[ind]
					ind += 1
					if ind == len(has):
						break
				elif num > 1 and c >= 48 and (c <= 57):
					num -= 1
					s[i] = has[ind]
					ind += 1
					if ind == len(has):
						break
			print(''.join(s))

		def read():
			t = int(input())
			for cas in range(t):
				solution()
		if __name__ == '__main__':
			read()
	except EOFError:
		break


for i in range(int(input())):
	s = input()
	if s.islower() and s.isalpha():
		s = list(s)
		(s[0], s[1]) = ('A', '1')
	elif s.isupper() and s.isalpha():
		s = list(s)
		(s[0], s[1]) = ('a', '1')
	elif s.isdigit():
		s = list(s)
		(s[0], s[1]) = ('A', 'a')
	else:
		s = list(s)
		(low, up, num) = (False, False, False)
		(lowin, upin, numin) = (0, 0, 0)
		(lowcnt, upcnt, numcnt) = (0, 0, 0)
		for i in range(len(s)):
			if ord(s[i]) >= 65 and ord(s[i]) <= 90:
				up = True
				upcnt += 1
				if upcnt > 1:
					upin = i
			if ord(s[i]) >= 97 and ord(s[i]) <= 122:
				low = True
				lowcnt += 1
				if lowcnt > 1:
					lowin = i
			if ord(s[i]) >= 48 and ord(s[i]) <= 57:
				num = True
				numcnt += 1
				if numcnt > 1:
					numin = i
		if low == False:
			if upin > 0:
				s[upin] = 'a'
			elif numin > 0:
				s[numin] = 'a'
		elif up == False:
			if lowin > 0:
				s[lowin] = 'A'
			elif numin > 0:
				s[numin] = 'A'
		elif num == False:
			if upin > 0:
				s[upin] = '1'
			elif lowin > 0:
				s[lowin] = '1'
	ans = ''
	for i in range(len(s)):
		ans += s[i]
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		ini = list(input())
		(cl, cu, cd) = ([], [], [])
		for j in range(len(ini)):
			if ini[j].islower():
				cl.append(j)
			elif ini[j].isupper():
				cu.append(j)
			else:
				cd.append(j)
		if len(cl) == len(ini):
			(ini[0], ini[1]) = ('A', '0')
		elif len(cu) == len(ini):
			(ini[0], ini[1]) = ('a', '0')
		elif len(cd) == len(ini):
			(ini[0], ini[1]) = ('a', 'A')
		elif not cl:
			if 1 < len(cu):
				ini[cu[0]] = 'a'
			else:
				ini[cd[0]] = 'a'
		elif not cu:
			if 1 < len(cl):
				ini[cl[0]] = 'A'
			else:
				ini[cd[0]] = 'A'
		elif not cd:
			if 1 < len(cl):
				ini[cl[0]] = '0'
			else:
				ini[cu[0]] = '0'
		print(''.join(ini))
main()


T = int(input())
num_pred = lambda ch: '0' <= ch <= '9'
down_pred = lambda ch: 'a' <= ch <= 'z'
up_pred = lambda ch: 'A' <= ch <= 'Z'

def categories(s):
	(n, d, u) = (0, 0, 0)
	for ch in s:
		if num_pred(ch):
			n += 1
		if down_pred(ch):
			d += 1
		if up_pred(ch):
			u += 1
	return (n, d, u)

def find_pos(s, pred):
	p = 0
	for i in range(len(s)):
		if pred(s[i]):
			p = i
			return p
	return 0

def change_str_p1(s, p, nch):
	chs = list(s)
	chs[p] = nch
	return ''.join(chs)

def change_str2(s, nch1, nch2):
	chs = list(s)
	chs[0] = nch1
	chs[1] = nch2
	return ''.join(chs)

def change(s):
	(n, d, u) = categories(s)
	if n > 0 and d > 0 and (u > 0):
		return s
	if n == 0:
		if d > 0 and u > 0:
			if d > 1:
				p = find_pos(s, down_pred)
				return change_str_p1(s, p, '1')
			else:
				p = find_pos(s, up_pred)
				return change_str_p1(s, p, '1')
		if d == 0:
			return change_str2(s, '1', 'a')
		if u == 0:
			return change_str2(s, '1', 'A')
	if d == 0:
		if n > 0 and u > 0:
			if n > 1:
				p = find_pos(s, num_pred)
				return change_str_p1(s, p, 'a')
			else:
				p = find_pos(s, up_pred)
				return change_str_p1(s, p, 'a')
		if u == 0:
			return change_str2(s, 'a', 'A')
	if u == 0:
		if d > 0 and n > 0:
			if d > 1:
				p = find_pos(s, down_pred)
				return change_str_p1(s, p, 'A')
			else:
				p = find_pos(s, num_pred)
				return change_str_p1(s, p, 'A')
for _ in range(T):
	s = input()
	print(change(s))


def is_correct(s):
	return bool([i for i in s if 'a' <= i <= 'z'] and [i for i in s if 'A' <= i <= 'Z'] and [i for i in s if '0' <= i <= '9'])
n = int(input())
ans = []

def gen_one(s):
	for i in range(len(s)):
		for j in ('0', 'a', 'A'):
			new_pass = s[:i] + j + s[i + 1:]
			if is_correct(new_pass):
				return new_pass
	return None
for i in range(n):
	password = input()
	if is_correct(password):
		ans.append(password)
		continue
	a = gen_one(password)
	if a:
		ans.append(a)
		continue
	if 'a' <= password[2] <= 'z':
		ans.append('A1' + password[2:])
		continue
	if 'A' <= password[2] <= 'Z':
		ans.append('a1' + password[2:])
		continue
	if '0' <= password[2] <= '9':
		ans.append('Aa' + password[2:])
		continue
for i in ans:
	print(i)


for _ in range(int(input())):
	s = list(input())
	(l, u, d) = (0, 0, 0)
	for i in range(len(s)):
		if s[i].islower():
			l += 1
		elif s[i].isupper():
			u += 1
		else:
			d += 1
	if l >= 1 and u >= 1 and (d >= 1):
		x = ''.join(s)
		print(x)
		continue
	if l == 0 and u == 0:
		s[0] = 'A'
		s[1] = 'a'
		x = ''.join(s)
		print(x)
	elif l == 0 and d == 0:
		s[0] = 'a'
		s[1] = '1'
		x = ''.join(s)
		print(x)
	elif u == 0 and d == 0:
		s[0] = 'A'
		s[1] = '1'
		x = ''.join(s)
		print(x)
	else:
		if l == 0:
			for i in range(len(s)):
				if s[i].isupper() and u > 1:
					s[i] = 'a'
					break
				if s[i].isdigit() and d > 1:
					s[i] = 'a'
					break
		elif u == 0:
			for i in range(len(s)):
				if s[i].islower() and l > 1:
					s[i] = 'A'
					break
				if s[i].isdigit() and d > 1:
					s[i] = 'A'
					break
		elif d == 0:
			for i in range(len(s)):
				if s[i].islower() and l > 1:
					s[i] = '1'
					break
				if s[i].isupper() and u > 1:
					s[i] = '1'
					break
		x = ''.join(s)
		print(x)


n = int(input())
for i in range(n):
	t = [x for x in input()]
	flags = [0, 0, 0]
	links = [-1, -1, -1]
	for j in range(len(t)):
		if t[j].isalpha() and t[j].lower() == t[j] and (flags[0] == 0):
			flags[0] = 1
			links[0] = j
		if t[j].isalpha() and t[j].lower() != t[j] and (flags[1] == 0):
			flags[1] = 1
			links[1] = j
		if t[j].isdigit() and flags[2] == 0:
			flags[2] = 1
			links[2] = j
	if sum(flags) == 2:
		if flags[0] == 0:
			if 0 in links:
				if 1 in links:
					t[2] = 'q'
				else:
					t[1] = 'q'
			else:
				t[0] = 'q'
		elif flags[1] == 0:
			if 0 in links:
				if 1 in links:
					t[2] = 'Q'
				else:
					t[1] = 'Q'
			else:
				t[0] = 'Q'
		elif 0 in links:
			if 1 in links:
				t[2] = '4'
			else:
				t[1] = '4'
		else:
			t[0] = '4'
	if sum(flags) == 1:
		if flags[0] != 0:
			if links[0] == 0:
				t[1] = 'Q'
				t[2] = '4'
			elif links[0] == 1:
				t[2] = 'Q'
				t[3] = '4'
			else:
				t[0] = 'Q'
				t[1] = '4'
		elif flags[1] != 0:
			if links[1] == 0:
				t[1] = 'q'
				t[2] = '4'
			elif links[1] == 1:
				t[2] = 'q'
				t[3] = '4'
			else:
				t[0] = 'q'
				t[1] = '4'
		elif links[2] == 0:
			t[1] = 'q'
			t[2] = 'Q'
		elif links[2] == 1:
			t[2] = 'q'
			t[3] = 'Q'
		else:
			t[0] = 'q'
			t[1] = 'Q'
	print(''.join(t))


def rmap():
	return map(int, input().split())

def rlist():
	return list(map(int, input().split()))

def rdi():
	return int(input())
n = rdi()
under = [chr(elem) for elem in range(ord('a'), ord('z') + 1)]
upper = [chr(elem) for elem in range(ord('A'), ord('Z') + 1)]
number = [chr(elem) for elem in range(ord('0'), ord('9') + 1)]
for i in range(n):
	line = [elem for elem in input()]
	under_l = []
	upper_l = []
	number_l = []
	for i in range(len(line)):
		if line[i] in under:
			under_l.append(i)
		elif line[i] in upper:
			upper_l.append(i)
		elif line[i] in number:
			number_l.append(i)
	if len(under_l) != 0 and len(upper_l) != 0 and (len(number_l) != 0):
		print(''.join(line))
	elif len(under_l) != 0 and len(upper_l) != 0 and (len(number_l) == 0):
		if len(under_l) > 1:
			line[under_l[0]] = '0'
		else:
			line[upper_l[0]] = '0'
		print(''.join(line))
	elif len(under_l) != 0 and len(upper_l) == 0 and (len(number_l) != 0):
		if len(under_l) > 1:
			line[under_l[0]] = 'A'
		else:
			line[number_l[0]] = 'A'
		print(''.join(line))
	elif len(under_l) == 0 and len(upper_l) != 0 and (len(number_l) != 0):
		if len(upper_l) > 1:
			line[upper_l[0]] = 'a'
		else:
			line[number_l[0]] = 'a'
		print(''.join(line))
	elif len(under_l) != 0:
		line[0] = 'A'
		line[1] = '1'
		print(''.join(line))
	elif len(upper_l) != 0:
		line[0] = 'a'
		line[1] = '1'
		print(''.join(line))
	elif len(number_l) != 0:
		line[0] = 'A'
		line[1] = 'a'
		print(''.join(line))


n = int(input())
for i in range(n):
	s = input()
	a = [0, 0, 0]
	for i in s:
		if ord(i) >= 48 and ord(i) <= 57:
			a[0] += 1
		elif ord(i) >= 65 and ord(i) <= 90:
			a[1] += 1
		elif ord(i) >= 97 and ord(i) <= 122:
			a[2] += 1
	if a[0] == 0 and a[1] >= 1 and (a[2] >= 1):
		if a[1] > 1:
			k = 0
			while not (ord(s[k]) >= 65 and ord(s[k]) <= 90):
				k += 1
			s = s[0:k] + '1' + s[k + 1:]
		elif a[2] > 1:
			k = 0
			while not (ord(s[k]) >= 97 and ord(s[k]) <= 122):
				k += 1
			s = s[0:k] + '1' + s[k + 1:]
	elif a[0] >= 1 and a[1] == 0 and (a[2] >= 1):
		if a[0] > 1:
			k = 0
			while not (ord(s[k]) >= 48 and ord(s[k]) <= 57):
				k += 1
			s = s[0:k] + 'A' + s[k + 1:]
		elif a[2] > 1:
			k = 0
			while not (ord(s[k]) >= 97 and ord(s[k]) <= 122):
				k += 1
			s = s[0:k] + 'A' + s[k + 1:]
	elif a[0] >= 1 and a[1] >= 1 and (a[2] == 0):
		if a[0] > 1:
			k = 0
			while not (ord(s[k]) >= 48 and ord(s[k]) <= 57):
				k += 1
			s = s[0:k] + 'a' + s[k + 1:]
		elif a[1] > 1:
			k = 0
			while not (ord(s[k]) >= 65 and ord(s[k]) <= 90):
				k += 1
			s = s[0:k] + 'a' + s[k + 1:]
	elif a[0] == 0 and a[1] == 0:
		s = 'A1' + s[2:]
	elif a[2] == 0 and a[1] == 0:
		s = 'aA' + s[2:]
	elif a[0] == 0 and a[2] == 0:
		s = '1a' + s[2:]
	print(s)


def solve(s):
	s = list(s)
	(loc, upc, dig) = (set(), set(), set())
	for i in range(len(s)):
		if s[i].islower():
			loc.add(i)
		elif s[i].isdigit():
			dig.add(i)
		else:
			upc.add(i)
	if len(loc) == 0 and len(upc) == 0:
		return 'aA' + ''.join(s[2:])
	elif len(loc) == 0 and len(dig) == 0:
		return 'a0' + ''.join(s[2:])
	elif len(upc) == 0 and len(dig) == 0:
		return 'A0' + ''.join(s[2:])
	if len(loc) == 0:
		tgt = upc if len(upc) > 1 else dig
		idx = tgt.pop()
		s[idx] = 'a'
	elif len(upc) == 0:
		tgt = dig if len(dig) > 1 else loc
		idx = tgt.pop()
		s[idx] = 'A'
	elif len(dig) == 0:
		tgt = loc if len(loc) > 1 else upc
		idx = tgt.pop()
		s[idx] = '0'
	return ''.join(s)

def driver():
	t = int(input())
	for _ in range(t):
		s = input()
		print(solve(s))
driver()


import re

def getLen(a):
	d = 0
	for i in a:
		d = d + len(i)
	return d

def exe(s):
	di = re.findall('\\d+', s)
	lo = re.findall('[a-z]+', s)
	up = re.findall('[A-Z]+', s)
	d = getLen(di)
	l = getLen(lo)
	u = getLen(up)
	if d and l and u:
		return s
	s = list(s)
	if not d and (not l):
		s[0] = '0'
		s[1] = 'a'
		return ''.join(s)
	if not d and (not u):
		s[0] = '0'
		s[1] = 'A'
		return ''.join(s)
	if not u and (not l):
		s[0] = 'A'
		s[1] = 'a'
		return ''.join(s)
	if not d:
		if l > 1:
			for i in range(len(s)):
				if s[i].islower():
					s[i] = '0'
					return ''.join(s)
		else:
			for i in range(len(s)):
				if s[i].isupper():
					s[i] = '0'
					return ''.join(s)
	if not l:
		if u > 1:
			for i in range(len(s)):
				if s[i].isupper():
					s[i] = 'a'
					return ''.join(s)
		else:
			for i in range(len(s)):
				if not s[i].isupper():
					s[i] = 'a'
					return ''.join(s)
	if not u:
		if l > 1:
			for i in range(len(s)):
				if s[i].islower():
					s[i] = 'A'
					return ''.join(s)
		else:
			for i in range(len(s)):
				if not s[i].islower():
					s[i] = 'A'
					return ''.join(s)
n = int(input())
for _ in range(n):
	s = input()
	print(exe(s))


def has_num(s):
	for i in s:
		if ord(i) >= 48 and ord(i) <= 57:
			return True
	return False

def has_capital(s):
	for i in s:
		if ord(i) >= 65 and ord(i) <= 90:
			return True
	return False

def has_small(s):
	for i in s:
		if ord(i) >= 97 and ord(i) <= 122:
			return True
	return False
t = int(input())
for i in range(t):
	s = input()
	p = has_num(s)
	q = has_capital(s)
	r = has_small(s)
	if p and q and r:
		print(s)
	elif p and (not q) and (not r):
		s = 'Aa' + s[2:]
		print(s)
	elif q and (not p) and (not r):
		s = '1a' + s[2:]
		print(s)
	elif r and (not p) and (not q):
		s = '1A' + s[2:]
		print(s)
	elif p and q and (not r):
		if has_capital('a' + s[1:]) and has_small('a' + s[1:]) and has_num('a' + s[1:]):
			print('a' + s[1:])
		elif has_capital(s[0] + 'a' + s[2:]) and has_small(s[0] + 'a' + s[2:]) and has_num(s[0] + 'a' + s[2:]):
			print(s[0] + 'a' + s[2:])
	elif p and r and (not q):
		if has_capital('A' + s[1:]) and has_small('A' + s[1:]) and has_num('A' + s[1:]):
			print('A' + s[1:])
		elif has_capital(s[0] + 'A' + s[2:]) and has_small(s[0] + 'A' + s[2:]) and has_num(s[0] + 'A' + s[2:]):
			print(s[0] + 'A' + s[2:])
	elif q and r and (not p):
		if has_capital('1' + s[1:]) and has_small('1' + s[1:]) and has_num('1' + s[1:]):
			print('1' + s[1:])
		elif has_capital(s[0] + '1' + s[2:]) and has_small(s[0] + '1' + s[2:]) and has_num(s[0] + '1' + s[2:]):
			print(s[0] + '1' + s[2:])


import string
n = int(input())
num = [0, 0, 0]
idx = [0, 0, 0]

def get(a):
	(num[0], num[1], num[2]) = (0, 0, 0)
	(idx[0], idx[1], idx[2]) = (0, 0, 0)
	for i in range(len(a)):
		c = a[i]
		if c in string.ascii_lowercase:
			num[0] += 1
			idx[0] = i
		if c in string.ascii_uppercase:
			num[1] += 1
			idx[1] = i
		if c in string.digits:
			num[2] += 1
			idx[2] = i
for i in range(n):
	a = str(input())
	get(a)
	if num[0] > 0 and num[1] > 0 and (num[2] > 0):
		print(a)
		continue
	ans = list(a)
	if num[0] > 0 and num[1] > 0:
		if num[0] > 1:
			ans[idx[0]] = '0'
		else:
			ans[idx[1]] = '0'
		print(''.join(ans))
		continue
	if num[1] > 0 and num[2] > 0:
		if num[1] > 1:
			ans[idx[1]] = 'a'
		else:
			ans[idx[2]] = 'a'
		print(''.join(ans))
		continue
	if num[0] > 0 and num[2] > 0:
		if num[0] > 1:
			ans[idx[0]] = 'A'
		else:
			ans[idx[2]] = 'A'
		print(''.join(ans))
		continue
	if num[0] > 0:
		(ans[0], ans[1]) = ('A', '1')
	elif num[1] > 0:
		(ans[0], ans[1]) = ('a', '1')
	else:
		(ans[0], ans[1]) = ('a', 'A')
	print(''.join(ans))


for i in range(int(input())):
	(s, u, l, dig) = (input(), 0, 0, 0)
	(ux, lx, digx) = ([], [], [])
	for j in s:
		if j.isdigit():
			dig += 1
			digx.append(j)
		elif j.isupper():
			u += 1
			ux.append(j)
		else:
			l += 1
			lx.append(j)
	if dig == 0:
		if u >= l:
			s = s.replace(ux[0], '3', 1)
		else:
			s = s.replace(lx[0], '3', 1)
	if u == 0:
		if l >= dig:
			s = s.replace(lx[1], 'A', 1)
		else:
			s = s.replace(digx[0], 'A', 1)
	if l == 0:
		if u >= dig:
			s = s.replace(ux[1], 'a', 1)
		else:
			s = s.replace(digx[1], 'a', 1)
	print(s)


n = int(input())

def func(s):
	sta = False
	stA = False
	st1 = False
	posa = -1
	posA = -1
	pos1 = -1
	k = len(s)
	for i in range(k):
		t = ord(s[i])
		if t <= 57 and t >= 48:
			st1 = True
			pos1 = i
		elif t >= 65 and t <= 90:
			stA += 1
			posA = i
		else:
			sta += 1
			posa = i
	if st1 and sta and stA:
		return s
	else:
		res = ''
		for i in range(k):
			if i != pos1 and i != posa and (i != posA):
				if not sta:
					res += 'a'
					posa = i
					sta = True
				elif not stA:
					res += 'A'
					posA = i
					stA = True
				elif not st1:
					res += '1'
					pos1 = i
					st1 = True
				else:
					res += s[i]
			else:
				res += s[i]
		return res
for i in range(n):
	s = input()
	print(func(s))


for i in range(int(input())):
	s = input()
	z = list(s)
	a = []
	a1 = 0
	A = []
	a2 = 0
	_0 = []
	a3 = 0
	for j in range(len(z)):
		if z[j].islower():
			a += [j]
			a1 += 1
		elif z[j].isupper():
			A += [j]
			a2 += 1
		else:
			_0 += [j]
			a3 = 1
	if a1 != 0 and a2 != 0 and (a3 != 0):
		print(*z, sep='')
	elif a1 == a2 == 0 or a2 == a3 == 0 or a1 == a3 == 0:
		if a1 != 0:
			z[a[0]] = '1'
			z[a[1]] = 'A'
			print(*z, sep='')
		elif a2 != 0:
			z[A[0]] = '1'
			z[A[1]] = 'a'
			print(*z, sep='')
		else:
			z[_0[0]] = 'a'
			z[_0[1]] = 'A'
			print(*z, sep='')
	else:
		if a1 == 0:
			if a2 > a3:
				z[A[0]] = 'a'
			else:
				z[_0[0]] = 'a'
		elif a2 == 0:
			if a1 > a3:
				z[a[0]] = 'A'
			else:
				z[_0[0]] = 'A'
		elif a2 > a1:
			z[A[0]] = '1'
		else:
			z[a[0]] = '1'
		print(*z, sep='')


t = int(input())
ans = [0] * t
o_b = 'A'
o_m = 'a'
o_ch = '1'
for i in range(t):
	a = input()
	l = len(a)
	s = [0] * l
	for j in range(l):
		s[j] = a[j]
	m_b = [0] * l
	m_m = [0] * l
	m_ch = [0] * l
	l_b = 0
	l_m = 0
	l_ch = 0
	for j in range(l):
		elem = s[j]
		if 'A' <= elem <= 'Z':
			m_b[l_b] = j
			l_b += 1
		elif '0' <= elem <= '9':
			m_ch[l_ch] = j
			l_ch += 1
		else:
			m_m[l_m] = j
			l_m += 1
	b_b = l_b > 0
	b_m = l_m > 0
	b_ch = l_ch > 0
	n = b_b + b_m + b_ch
	if n == 2:
		if not b_b:
			if l_m > 1:
				s[m_m[0]] = o_b
			else:
				s[m_ch[0]] = o_b
		elif not b_m:
			if l_b > 1:
				s[m_b[0]] = o_m
			else:
				s[m_ch[0]] = o_m
		elif l_b > 1:
			s[m_b[0]] = o_ch
		else:
			s[m_m[0]] = o_ch
	elif n == 1:
		if b_b:
			s[0] = o_m
			s[1] = o_ch
		elif b_m:
			s[0] = o_b
			s[1] = o_ch
		else:
			s[0] = o_b
			s[1] = o_m
	ans[i] = s
for i in range(t):
	print(*ans[i], sep='')


n = int(input())
dl = '1234567890'
cl = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
sl = 'abcdefghijklmnopqrstuvwxyz'
while n != 0:
	(d, c, sm) = ([], [], [])
	n -= 1
	s = input()
	for i in range(len(s)):
		if s[i] in dl:
			d.append(i)
		elif s[i] in cl:
			c.append(i)
		else:
			sm.append(i)
	if len(d) * len(c) * len(sm) > 0:
		print(s)
	else:
		s = list(s)
		if len(d) == 0:
			if len(c) == 0:
				s[0] = '1'
				s[1] = 'A'
			elif len(sm) == 0:
				s[0] = '1'
				s[1] = 'a'
			elif len(c) >= len(sm):
				s[c[0]] = '1'
			else:
				s[sm[0]] = '1'
		elif len(c) == 0:
			if len(sm) == 0:
				s[0] = 'A'
				s[1] = 'a'
			elif len(d) >= len(sm):
				s[d[0]] = 'A'
			else:
				s[sm[0]] = 'A'
		elif len(d) >= len(c):
			s[d[0]] = 'a'
		else:
			s[c[0]] = 'a'
		print(''.join(s))


cases = int(input())
for case in range(cases):
	s = input()
	t1 = False
	c1 = 0
	q1 = []
	t2 = False
	c2 = 0
	q2 = []
	t3 = False
	c3 = 0
	q3 = []
	for i in s:
		if ord(i) >= 97 and ord(i) <= 122:
			c1 += 1
			t1 = True
			q1.append(i)
		elif ord(i) >= 65 and ord(i) <= 90:
			c2 += 1
			t2 = True
			q2.append(i)
		elif ord(i) >= 48 and ord(i) <= 57:
			c3 += 1
			t3 = True
			q3.append(i)
	if t1 == False and t2 == False:
		s = 'aA' + s[2:]
		t1 = True
		t2 = True
	if t3 == False and t2 == False:
		s = '1A' + s[2:]
		t3 = True
		t2 = True
	if t1 == False and t3 == False:
		s = 'a1' + s[2:]
		t1 = True
		t3 = True
	if t1 == False:
		if c2 > c3:
			s = s.replace(q2[-1], 'a', 1)
			q2.pop()
			c2 -= 1
		else:
			s = s.replace(q3[-1], 'a', 1)
			q3.pop()
			c3 -= 1
	if t2 == False:
		if c1 > c3:
			s = s.replace(q1[-1], 'A', 1)
			q1.pop()
			c1 -= 1
		else:
			s = s.replace(q3[-1], 'A', 1)
			q3.pop()
			c3 -= 1
	if t3 == False:
		if c2 > c1:
			s = s.replace(q2[-1], '1', 1)
			q2.pop()
			c2 -= 1
		else:
			s = s.replace(q1[-1], '1', 1)
			q1.pop()
			c1 -= 1
	print(s)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	s = input()
	(a, b, c) = (0, 0, 0)
	n = len(s)
	for i in s:
		if i.isdigit():
			a += 1
		elif i.isupper():
			b += 1
		else:
			c += 1
	if a and b and c:
		print(s)
	elif b == c == 0:
		print(s[:n - 2] + 'a' + 'A')
	elif a == b == 0:
		print(s[:n - 2] + '1' + 'A')
	elif a == c == 0:
		print(s[:n - 2] + '1' + 'a')
	else:
		T = [*s]
		if a == 0:
			if b > 1:
				for i in range(len(T)):
					if T[i].isupper():
						T[i] = '1'
						break
			elif c > 1:
				for i in range(len(T)):
					if T[i].islower():
						T[i] = '1'
						break
			else:
				T[-1] = '1'
		if b == 0:
			if a > 1:
				for i in range(len(T)):
					if T[i].isdigit():
						T[i] = 'A'
						break
			elif c > 1:
				for i in range(len(T)):
					if T[i].islower():
						T[i] = 'A'
						break
			else:
				T[-1] = 'A'
		if c == 0:
			if b > 1:
				for i in range(len(T)):
					if T[i].isupper():
						T[i] = 'a'
						break
			elif a > 1:
				for i in range(len(T)):
					if T[i].isdigit():
						T[i] = 'a'
						break
			else:
				T[-1] = 'a'
		print(''.join(T))


import sys

def minp():
	return sys.stdin.readline().strip()
w = ['abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789']
rep = ['a', 'A', '0', 'aa', 'aA', 'a0', 'Aa', 'AA', 'A0', '0a', '0A', '00', 'aaa', 'aaA', 'aa0', 'aAa', 'aAA', 'aA0', 'a0a', 'a0A', 'a00', 'Aaa', 'AaA', 'Aa0', 'AAa', 'AAA', 'AA0', 'A0a', 'A0A', 'A00', '0aa', '0aA', '0a0', '0Aa', '0AA', '0A0', '00a', '00A', '000']
T = int(minp())
for t in range(T):
	s = minp()
	sums = [0, 0, 0]
	for i in range(len(s)):
		for k in range(3):
			if w[k].find(s[i]) != -1:
				sums[k] += 1
	if sums[0] > 0 and sums[1] > 0 and (sums[2] > 0):
		print(s)
		continue
	zz = [0, 0, 0]
	r = None
	for i in range(len(s)):
		for k in rep:
			if i + len(k) <= len(s):
				for kk in range(3):
					zz[kk] = sums[kk]
				for j in range(len(k)):
					for kk in range(3):
						if w[kk].find(s[i + j]) != -1:
							zz[kk] -= 1
						if w[kk].find(k[j]) != -1:
							zz[kk] += 1
				if zz[0] > 0 and zz[1] > 0 and (zz[2] > 0):
					if r == None:
						r = (i, k)
					elif len(r[1]) > len(k):
						r = (i, k)
	print(s[0:r[0]] + r[1] + s[r[0] + len(r[1]):])


for _ in [0] * int(input()):
	s = list(input())
	l = [0] * 3
	for (i, c) in enumerate(s, 1):
		j = (c > '9') + (c > 'Z')
		l[j] = l[j] or i
	for i in range(len(s)):
		for j in range(3):
			if l[j] < 1 and i + 1 not in l:
				s[i] = '0As'[j]
				l[j] = i + 1
	print(''.join(s))


t = int(input())
for i in range(t):
	s = input()
	a = []
	A = []
	d = []
	n = len(s)
	for j in range(n):
		if ord(s[j]) >= ord('a') and ord(s[j]) <= ord('z'):
			a.append(j)
		elif ord(s[j]) >= ord('A') and ord(s[j]) <= ord('Z'):
			A.append(j)
		else:
			d.append(j)
	if a and A and d:
		print(s)
	else:
		if not a:
			if len(A) > 1:
				s = s[:A[0]] + 'a' + s[A[0] + 1:]
				A.pop(0)
			else:
				s = s[:d[0]] + 'a' + s[d[0] + 1:]
				d.pop(0)
		if not A:
			if len(a) > 1:
				s = s[:a[0]] + 'A' + s[a[0] + 1:]
				a.pop(0)
			else:
				s = s[:d[0]] + 'A' + s[d[0] + 1:]
				d.pop(0)
		if not d:
			if len(A) > 1:
				s = s[:A[0]] + '1' + s[A[0] + 1:]
				A.pop(0)
			else:
				s = s[:a[0]] + '1' + s[a[0] + 1:]
				a.pop(0)
		print(s)


import re
numTestCases = int(input())

def isValid(pwd):
	hasUpper = re.search('[A-Z]', pwd)
	hasLower = re.search('[a-z]', pwd)
	hasDigit = re.search('[0-9]', pwd)
	if hasUpper and hasLower and hasDigit:
		return True
	return False
for i in range(numTestCases):
	pwd = input()
	if isValid(pwd):
		print(pwd)
	else:
		newPwd = ''
		for i in range(len(pwd)):
			pwdList = list(pwd)
			pwdList[i] = 'a'
			if isValid(''.join(pwdList)):
				newPwd = ''.join(pwdList)
				break
			pwdList[i] = 'A'
			if isValid(''.join(pwdList)):
				newPwd = ''.join(pwdList)
				break
			pwdList[i] = '1'
			if isValid(''.join(pwdList)):
				newPwd = ''.join(pwdList)
				break
		if not newPwd:
			if pwd[2].isupper():
				newPwd = 'a1' + pwd[2:]
			elif pwd[2].islower():
				newPwd = 'A1' + pwd[2:]
			else:
				newPwd = 'aA' + pwd[2:]
		print(newPwd)


def main():
	dig = set()
	for val in range(10):
		dig.add(str(val))
	for _ in range(int(input())):
		s = input()
		n = len(s)
		nums = []
		lc = []
		uc = []
		for i in range(n):
			if s[i] in dig:
				nums.append(i)
			elif s[i] == s[i].lower():
				lc.append(i)
			else:
				uc.append(i)
		if len(nums) and len(lc) and len(uc):
			print(s)
			continue
		if len(nums) and (not (len(lc) or len(uc))):
			print('aA' + s[2:])
			continue
		if len(lc) and (not (len(nums) or len(uc))):
			print('1A' + s[2:])
			continue
		if len(uc) and (not (len(lc) or len(nums))):
			print('a1' + s[2:])
			continue
		if not len(uc):
			if len(lc) > len(nums):
				for i in range(n):
					if i == lc[0]:
						print('A', end='')
					else:
						print(s[i], end='')
			else:
				for i in range(n):
					if i == nums[0]:
						print('A', end='')
					else:
						print(s[i], end='')
			print()
			continue
		if not len(lc):
			if len(uc) > len(nums):
				for i in range(n):
					if i == uc[0]:
						print('a', end='')
					else:
						print(s[i], end='')
			else:
				for i in range(n):
					if i == nums[0]:
						print('a', end='')
					else:
						print(s[i], end='')
			print()
			continue
		if not len(nums):
			if len(lc) > len(uc):
				for i in range(n):
					if i == lc[0]:
						print('1', end='')
					else:
						print(s[i], end='')
			else:
				for i in range(n):
					if i == uc[0]:
						print('1', end='')
					else:
						print(s[i], end='')
			print()
			continue
main()


def change(s):
	ks = 0
	kb = 0
	k1 = 0
	c = []
	for i in range(len(s)):
		x = ord(s[i])
		if x >= 97 and x <= 122:
			ks += 1
			c.append(0)
		elif x >= 65 and x <= 90:
			kb += 1
			c.append(1)
		else:
			k1 += 1
			c.append(2)
	if ks == 0 and kb == 0:
		return 'Aa' + s[2:]
	if ks == 0 and k1 == 0:
		return 'a1' + s[2:]
	if kb == 0 and k1 == 0:
		return 'A1' + s[2:]
	if ks != 0 and kb != 0 and (k1 != 0):
		return s
	if ks == 0:
		if kb >= 2:
			pos = c.index(1)
		else:
			pos = c.index(2)
		return s[:pos] + 'a' + s[pos + 1:]
	if kb == 0:
		if ks >= 2:
			pos = c.index(0)
		else:
			pos = c.index(2)
		return s[:pos] + 'A' + s[pos + 1:]
	if k1 == 0:
		if ks >= 2:
			pos = c.index(0)
		else:
			pos = c.index(1)
		return s[:pos] + '1' + s[pos + 1:]
t = int(input())
pas = []
for i in range(t):
	pas.append(input())
for i in range(t):
	print(change(pas[i]))


t = int(input())
for _ in range(t):
	s = input()
	digits = []
	upper = []
	lower = []
	i = 0
	d = 0
	u = 0
	l = 0
	for c in s:
		if ord(c) >= ord('0') and ord(c) <= ord('9'):
			digits.append(i)
			d += 1
		elif ord(c) >= ord('A') and ord(c) <= ord('Z'):
			upper.append(i)
			u += 1
		elif ord(c) >= ord('a') and ord(c) <= ord('z'):
			lower.append(i)
			l += 1
		i += 1
	if d == 0 and u == 0 and (l == 0):
		print('aA1' + s[3:])
		continue
	if d == 0:
		if u > 1:
			s = s[:upper[0]] + '1' + s[upper[0] + 1:]
			upper = upper[1:]
			u -= 1
		else:
			s = s[:lower[0]] + '1' + s[lower[0] + 1:]
			lower = lower[1:]
			l -= 1
	if u == 0:
		if l > 1:
			s = s[:lower[0]] + 'A' + s[lower[0] + 1:]
			l -= 1
			lower = lower[1:]
		else:
			s = s[:digits[0]] + 'A' + s[digits[0] + 1:]
			d -= 1
			digits = digits[1:]
	if l == 0:
		if d > 1:
			s = s[:digits[0]] + 'a' + s[digits[0] + 1:]
			d -= 1
			digits = digits[1:]
		else:
			s = s[:upper[0]] + 'a' + s[upper[0] + 1:]
	print(s)


from collections import defaultdict
t = int(input().rstrip())
for _ in range(t):
	s = list(input().strip())
	n = len(s)
	c = defaultdict(int)
	a = [0] * n
	for i in range(n):
		if s[i] >= 'a':
			c[1] += 1
			a[i] = 1
		elif s[i] >= 'A':
			c[2] += 1
			a[i] = 2
		else:
			c[3] += 1
			a[i] = 3
	if not c[1] and (not c[2]):
		s[0] = 'a'
		s[1] = 'A'
	elif not c[1] and (not c[3]):
		s[0] = 'a'
		s[1] = '1'
	elif not c[2] and (not c[3]):
		s[0] = 'A'
		s[1] = '1'
	elif not c[1]:
		if c[a[0]] > 1:
			s[0] = 'a'
		else:
			s[1] = 'a'
	elif not c[2]:
		if c[a[0]] > 1:
			s[0] = 'A'
		else:
			s[1] = 'A'
	elif not c[3]:
		if c[a[0]] > 1:
			s[0] = '1'
		else:
			s[1] = '1'
	print(''.join(s))


import re
T = int(input())
stroki = []
par = []
for i in range(T):
	par.append([0, 0, 0])
for i in range(T):
	stroki.append(input())
for i in range(T):
	for j in stroki[i]:
		if re.search('[0-9]+', j) != None:
			par[i][0] += 1
		if re.search('[A-Z]+', j) != None:
			par[i][1] += 1
		if re.search('[a-z]+', j) != None:
			par[i][2] += 1
for i in range(T):
	stroki[i] = list(stroki[i])
for i in range(T):
	if par[i][0] == 0:
		if par[i][1] > 1:
			stroki[i][re.search('[A-Z]+', ''.join(stroki[i])).span()[1] - 1] = '0'
		elif par[i][2] > 1:
			stroki[i][re.search('[a-z]+', ''.join(stroki[i])).span()[1] - 1] = '0'
	if par[i][1] == 0:
		if par[i][0] > 1:
			stroki[i][re.search('[0-9]+', ''.join(stroki[i])).span()[1] - 1] = 'A'
		elif par[i][2] > 1:
			stroki[i][re.search('[a-z]+', ''.join(stroki[i])).span()[1] - 1] = 'A'
	if par[i][2] == 0:
		if par[i][0] > 1:
			stroki[i][re.search('[0-9]+', ''.join(stroki[i])).span()[1] - 1] = 'a'
		elif par[i][1] > 1:
			stroki[i][re.search('[A-Z]+', ''.join(stroki[i])).span()[1] - 1] = 'a'
	print(''.join(stroki[i]))


t = int(input())
for i in range(t):
	s = input()
	last = list(s)
	a = [0] * 3
	ind = []
	for i in range(3):
		ind.append([])
	pos = 0
	for cha in s:
		if ord(cha) >= ord('0') and ord(cha) <= ord('9'):
			a[0] += 1
			ind[0].append(pos)
		elif ord(cha) >= ord('A') and ord(cha) <= ord('Z'):
			a[1] += 1
			ind[1].append(pos)
		else:
			a[2] += 1
			ind[2].append(pos)
		pos += 1
	arr = []
	for j in range(3):
		if a[j] == 0:
			arr.append(j)
	if len(arr) == 0:
		print(s)
	else:
		for j in range(3):
			if a[j] > 1:
				mai = j
				break
		while len(arr) != 0:
			pos = arr.pop()
			if pos == 0:
				last[ind[mai].pop()] = '3'
			elif pos == 1:
				last[ind[mai].pop()] = 'C'
			else:
				last[ind[mai].pop()] = 'c'
		ans = ''.join(last)
		print(ans)


t = int(input())
for cas in range(t):
	st = input()
	low = list('abcdefghijklmnopqrstuvwxyz')
	upp = [x.upper() for x in low]
	num = list('1234567890')
	com = {'l': 0, 'u': 0, 'n': 0}
	changed = {'l': low, 'u': upp, 'n': num}
	for c in st:
		if c in low:
			com['l'] = com['l'] + 1
		elif c in upp:
			com['u'] = com['u'] + 1
		else:
			com['n'] = com['n'] + 1
	ans = list(st)[:]
	count = 3
	ctype = []
	for x in com:
		if com[x] == 0:
			count = count - 1
			ctype.append(x)
	if count == 2:
		mi = 2
		for x in com:
			if com[x] >= 2:
				flip = x
		for i in range(len(ans)):
			if ans[i] in changed[flip]:
				ans[i] = changed[ctype[0]][0]
				break
	elif count == 1:
		ans[0] = changed[ctype[0]][0]
		ans[1] = changed[ctype[1]][0]
	print(''.join(ans))


num = int(input())
list = []
for i in range(0, num):
	list.append([s for s in input()])
for s in list:
	for i in range(0, 3):
		lowercase = 0
		uppercase = 0
		digit = 0
		first_lower = -1
		first_upper = -1
		first_digit = -1
		for i in range(0, len(s)):
			if s[i].isupper():
				if first_upper == -1:
					first_upper = i
				uppercase = uppercase + 1
			elif s[i].islower():
				if first_lower == -1:
					first_lower = i
				lowercase = lowercase + 1
			else:
				if first_digit == -1:
					first_digit = i
				digit = digit + 1
		if digit == 0:
			if lowercase > 1:
				s[first_lower] = '0'
			else:
				s[first_upper] = '0'
		elif lowercase == 0:
			if uppercase > 1:
				s[first_upper] = 'a'
			else:
				s[first_digit] = 'a'
		elif uppercase == 0:
			if lowercase > 1:
				s[first_lower] = 'A'
			else:
				s[first_digit] = 'A'
for s in list:
	for i in s:
		print(i, end='')
	print()


t = int(input())
for i in range(t):
	s = list(input())
	(cntup, cntlow, cntnum) = (0, 0, 0)
	(lastu, lastl, lastd) = (-1, -1, -1)
	for i in range(len(s)):
		if s[i].isupper():
			lastu = i
			cntup += 1
		if s[i].islower():
			lastl = i
			cntlow += 1
		if s[i].isdigit():
			lastd = i
			cntnum += 1
	if cntnum == 0 and cntlow == 0:
		s[0] = '1'
		s[1] = 'a'
	elif cntnum == 0 and cntup == 0:
		s[0] = '1'
		s[1] = 'A'
	elif cntup == 0 and cntlow == 0:
		s[0] = 'A'
		s[1] = 'a'
	elif cntnum == 0:
		if cntup >= cntlow:
			s[lastu] = '1'
		else:
			s[lastl] = '1'
	elif cntup == 0:
		if cntnum >= cntlow:
			s[lastd] = 'A'
		else:
			s[lastl] = 'A'
	elif cntlow == 0:
		if cntup >= cntnum:
			s[lastu] = 'a'
		else:
			s[lastd] = 'a'
	s1 = ''
	for x in s:
		s1 += x
	print(s1)


n = int(input())
for i in range(n):
	s = input()
	mal = []
	bol = []
	cif = []
	for i in range(len(s)):
		if s[i] >= 'a' and s[i] <= 'z':
			mal.append(i)
		if s[i] >= 'A' and s[i] <= 'Z':
			bol.append(i)
		if s[i] >= '0' and s[i] <= '9':
			cif.append(i)
	if len(mal) > 0 and len(bol) > 0 and (len(cif) > 0):
		print(s)
	elif len(mal) > 0 and len(bol) > 0:
		if len(mal) > 1:
			print(s[:mal[0]] + '1' + s[mal[0] + 1:])
		else:
			print(s[:bol[0]] + '1' + s[bol[0] + 1:])
	elif len(mal) > 0 and len(cif) > 0:
		if len(mal) > 1:
			print(s[:mal[0]] + 'A' + s[mal[0] + 1:])
		else:
			print(s[:cif[0]] + 'A' + s[cif[0] + 1:])
	elif len(bol) > 0 and len(cif) > 0:
		if len(bol) > 1:
			print(s[:bol[0]] + 'a' + s[bol[0] + 1:])
		else:
			print(s[:cif[0]] + 'a' + s[cif[0] + 1:])
	elif len(mal) > 0:
		print('1A' + s[2:])
	elif len(bol) > 0:
		print('1a' + s[2:])
	else:
		print('aA' + s[2:])


import string
(t,) = map(int, input().split())

def invalid(s):
	l = len(list(filter(lambda x: x in string.ascii_lowercase, s)))
	u = len(list(filter(lambda x: x in string.ascii_uppercase, s)))
	d = len(list(filter(lambda x: x in string.digits, s)))
	return any((l == 0, u == 0, d == 0))

def gen_str(s):
	l = len(list(filter(lambda x: x in string.ascii_lowercase, s)))
	u = len(list(filter(lambda x: x in string.ascii_uppercase, s)))
	d = len(list(filter(lambda x: x in string.digits, s)))
	rv = ''
	if l == 0:
		rv += 'a'
	if u == 0:
		rv += 'A'
	if d == 0:
		rv += '0'
	return rv
for _ in range(t):
	s = input()
	new_s = s
	if invalid(s):
		t = gen_str(s)
		new_s = t + s[len(t):]
		if invalid(new_s):
			new_s = s[:-len(t)] + t
	print(new_s)


t = int(input())
while t > 0:
	t -= 1
	n = input()
	arr = list(n)
	digit = 0
	small = 0
	upper = 0
	for i in arr:
		if i.isdigit():
			digit += 1
		elif ord(i) >= 65 and ord(i) <= 90:
			upper += 1
		elif ord(i) >= 97 and ord(i) <= 122:
			small += 1
	if small >= 1 and digit >= 1 and (upper >= 1):
		print(n)
	else:
		if digit < 1:
			if small >= upper:
				for i in range(len(arr)):
					if ord(arr[i]) >= 97 and ord(arr[i]) <= 122:
						arr[i] = '1'
						break
			else:
				for i in range(len(arr)):
					if ord(arr[i]) >= 65 and ord(arr[i]) <= 90:
						arr[i] = '1'
						break
		if small < 1:
			if digit >= upper:
				for i in range(len(arr)):
					if arr[i].isdigit():
						arr[i] = 'a'
						break
			else:
				for i in range(len(arr)):
					if ord(arr[i]) >= 65 and ord(arr[i]) <= 90:
						arr[i] = 'a'
						break
		if upper < 1:
			if small >= digit:
				for i in range(len(arr)):
					if ord(arr[i]) >= 97 and ord(arr[i]) <= 122:
						arr[i] = 'A'
						break
			else:
				for i in range(len(arr)):
					if arr[i].isdigit():
						arr[i] = 'A'
						break
		n = ''.join(arr)
		print(n)


n = int(input())
for i in range(n):
	lowcase = 0
	upcase = 0
	dig = 0
	s = input()
	res = ''
	for elem in s:
		if elem.isdigit():
			dig += 1
		elif elem.islower():
			lowcase += 1
		elif elem.isupper():
			upcase += 1
	if not all([lowcase, upcase, dig]):
		for i in s:
			if i.isdigit() and (not all([lowcase, upcase, dig])) and (dig > 1):
				if not lowcase:
					lowcase += 1
					res += 'a'
				elif not upcase:
					upcase += 1
					res += 'A'
				dig -= 1
			elif i.isupper() and (not all([lowcase, upcase, dig])) and (upcase > 1):
				if not dig:
					dig += 1
					res += '1'
				elif not lowcase:
					lowcase += 1
					res += 'a'
				upcase -= 1
			elif i.islower() and (not all([lowcase, upcase, dig])) and (lowcase > 1):
				if not dig:
					dig += 1
					res += '1'
				elif not upcase:
					upcase += 1
					res += 'A'
				lowcase -= 1
			else:
				res += i
		print(res)
	else:
		print(s)


nums = '1234567890'
small = 'qwertyuiopasdfghjklzxcvbnm'
big = 'QWERTYUIOPASDFGHJKLZXCVBNM'
n = int(input())
for i in range(n):
	a = input()
	(nn, s, b) = (False, False, False)
	change = list()
	(nu, sm, bi) = (0, 0, 0)
	for (x, j) in enumerate(a):
		if j in nums:
			nu += 1
		if j in small:
			sm += 1
		if j in big:
			bi += 1
		if j in nums and nn is False:
			nn = True
			continue
		if j in small and s is False:
			s = True
			continue
		if j in big and b is False:
			b = True
			continue
		if j in nums and nn is True:
			change.append(x)
			continue
		if j in small and s is True:
			change.append(x)
			continue
		if j in big and b is True:
			change.append(x)
			continue
	q = [nn, s, b].count(False)
	w = 10000
	start = 0
	for j in range(q, len(change)):
		if change[j - q] - change[j] < w:
			w = change[j - q] - change[j]
			start = j - q
	for j in range(start, len(a)):
		if s and nn and b:
			break
		if a[j] in nums and nu == 1:
			continue
		if a[j] in big and bi == 1:
			continue
		if a[j] in small and sm == 1:
			continue
		if nn is False:
			nn = True
			a = a[:j] + '1' + a[j + 1:]
			continue
		if s is False:
			s = True
			a = a[:j] + 'a' + a[j + 1:]
			continue
		if b is False:
			b = True
			a = a[:j] + 'A' + a[j + 1:]
	print(a)


n = int(input())
for i in range(n):
	s = input()
	a = [0, 0, 0]
	for let in s:
		if let >= 'A' and let <= 'Z':
			a[0] += 1
		elif let >= 'a' and let <= 'z':
			a[1] += 1
		elif let >= '0' and let <= '9':
			a[2] += 1
	if a[0] > 0 and a[1] > 0 and (a[2] > 0):
		print(s)
	else:
		if a[0] == 0:
			if a[1] == 0:
				s = 'Aa' + s[2:]
			elif a[2] == 0:
				s = 'A0' + s[2:]
			elif a[1] > 1:
				for (ind, k) in enumerate(s):
					if k >= 'a' and k <= 'z':
						s = s[:ind] + 'A' + s[ind + 1:]
						break
			elif a[2] > 1:
				for (ind, k) in enumerate(s):
					if k >= '0' and k <= '9':
						s = s[:ind] + 'A' + s[ind + 1:]
						break
		elif a[1] == 0:
			if a[2] == 0:
				s = 'a0' + s[2:]
			elif a[0] > 1:
				for (ind, k) in enumerate(s):
					if k >= 'A' and k <= 'Z':
						s = s[:ind] + 'a' + s[ind + 1:]
						break
			elif a[2] > 1:
				for (ind, k) in enumerate(s):
					if k >= '0' and k <= '9':
						s = s[:ind] + 'a' + s[ind + 1:]
						break
		elif a[2] == 0:
			if a[0] > 1:
				for (ind, k) in enumerate(s):
					if k >= 'A' and k <= 'Z':
						s = s[:ind] + '0' + s[ind + 1:]
						break
			elif a[1] > 1:
				for (ind, k) in enumerate(s):
					if k >= 'a' and k <= 'z':
						s = s[:ind] + '0' + s[ind + 1:]
						break
		print(s)


import sys
from array import array

def readline() -> str:
	return sys.stdin.buffer.readline().decode('utf-8')
t = int(readline())
for _ in range(t):
	s = readline().rstrip()
	(num, lower, upper) = (0, 0, 0)
	for c in s:
		if ord(c) >= 97:
			lower += 1
		elif ord(c) >= 65:
			upper += 1
		else:
			num += 1
	if num and lower and upper:
		print(s)
		continue
	if not num and (not lower):
		print('1a' + s[2:])
	elif not num and (not upper):
		print('1A' + s[2:])
	elif not lower and (not upper):
		print('aA' + s[2:])
	else:
		x = '1' if not num else 'a' if not lower else 'A'
		for i in range(len(s)):
			if ord(s[i]) >= 97 and lower > 1:
				print(s[:i] + x + s[i + 1:])
				break
			if 65 <= ord(s[i]) < 97 and upper > 1:
				print(s[:i] + x + s[i + 1:])
				break
			if ord(s[i]) < 65 and num > 1:
				print(s[:i] + x + s[i + 1:])
				break


from sys import stdin, stdout, exit

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
digs = '0123456789'
lowercase = 'abcdefghijklmnopqrstuvwxyz'
uppercase = lowercase.upper()

def ispassword(s):
	return any([i in s for i in digs]) and any([i in s for i in lowercase]) and any([i in s for i in uppercase])

def changes(s1, s2):
	cnt = 0
	if s1[0] != s2[0] and (s1[0].islower() == s2[0].isupper() or s1[0].islower() == s2[0].isdigit() or s1[0].isdigit() == s2[0].isupper()):
		cnt += 1
	if s1[1] != s2[1] and (s1[1].islower() == s2[1].isupper() or s1[1].islower() == s2[1].isdigit() or s1[1].isdigit() == s2[1].isupper()):
		cnt += 1
	return cnt
t = int(sin())
for _ in range(t):
	s = sin()
	min_ans = 3
	min_string = s
	for i in range(len(s) - 1):
		tries = []
		for a in (s[i], s[i].upper() if s[i].islower() else s[i].lower(), '0') if not s[i].isdigit() else (s[i], 'a', 'A'):
			for b in (s[i + 1], s[i + 1].upper() if s[i + 1].islower() else s[i + 1].lower(), '0') if not s[i + 1].isdigit() else (s[i + 1], 'a', 'A'):
				tries.append(a + b)
		for tri in tries:
			if ispassword(s[:i] + tri + s[i + 2:]):
				temp_ans = changes(s[i:i + 2], tri)
				if temp_ans < min_ans:
					min_string = s[:i] + tri + s[i + 2:]
					min_ans = temp_ans
	print(min_string)


import sys
t = int(sys.stdin.readline())
a = ord('a')
z = ord('z')
A = ord('A')
Z = ord('Z')
zero = ord('0')
nine = ord('9')
for i in range(t):
	f1 = 0
	f2 = 0
	f3 = 0
	c1 = 0
	c2 = 0
	c3 = 0
	ip = list(sys.stdin.readline())
	ip = ip[:len(ip) - 1]
	for j in ip:
		x = ord(j)
		if x >= a and x <= z:
			f1 = 1
			c1 = c1 + 1
		elif x >= A and x <= Z:
			f2 = 1
			c2 = c2 + 1
		elif x >= zero and x <= nine:
			f3 = 1
			c3 = c3 + 1
	if f1 and f2 and f3:
		print(''.join(ip))
		continue
	l = len(ip)
	if f1 and f2:
		if c1 >= c2:
			for j in range(l):
				x = ord(ip[j])
				if x >= a and x <= z:
					ip[j] = '1'
					break
		else:
			for j in range(l):
				x = ord(ip[j])
				if x >= A and x <= Z:
					ip[j] = '1'
					break
		print(''.join(ip))
		continue
	elif f2 and f3:
		if c2 >= c3:
			for j in range(l):
				x = ord(ip[j])
				if x >= A and x <= Z:
					ip[j] = 'a'
					break
		else:
			for j in range(l):
				x = ord(ip[j])
				if x >= zero and x <= nine:
					ip[j] = 'a'
					break
		print(''.join(ip))
		continue
	elif f3 and f1:
		if c3 >= c1:
			for j in range(l):
				x = ord(ip[j])
				if x >= zero and x <= nine:
					ip[j] = 'A'
					break
		else:
			for j in range(l):
				x = ord(ip[j])
				if x >= a and x <= z:
					ip[j] = 'A'
					break
		print(''.join(ip))
		continue
	if f1:
		ip[0] = '1'
		ip[1] = 'A'
	if f2:
		ip[0] = 'a'
		ip[1] = '1'
	if f3:
		ip[0] = 'A'
		ip[1] = 'a'
	print(''.join(ip))
	continue


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7

def inpl():
	return list(map(int, input().split()))

def inpls():
	return list(input().split())
N = int(input())
SS = [input() for i in range(N)]
for S in SS:
	flags = [0] * 3
	inds = [0] * 3
	for (i, s) in enumerate(S):
		if s.isdecimal():
			flags[0] += 1
			inds[0] = i
		elif s.isupper():
			flags[1] += 1
			inds[1] = i
		else:
			flags[2] += 1
			inds[2] = i
	tmp = 0
	for i in range(3):
		if flags[i] > 0:
			tmp += 1
	ans = list(S)
	if tmp == 3:
		print(S)
	elif tmp == 2:
		if flags[0] == 0:
			if flags[1] > 1:
				ans[inds[1]] = '1'
			else:
				ans[inds[2]] = '1'
		elif flags[1] == 0:
			if flags[2] > 1:
				ans[inds[2]] = 'A'
			else:
				ans[inds[0]] = 'A'
		elif flags[2] == 0:
			if flags[0] > 1:
				ans[inds[0]] = 'a'
			else:
				ans[inds[1]] = 'a'
		print(''.join(ans))
	elif tmp == 1:
		if flags[0] > 0:
			print('aA' + S[2:])
		if flags[1] > 0:
			print('1a' + S[2:])
		if flags[2] > 0:
			print('1A' + S[2:])


sym = ['A', 'a', '1']
t = int(input())
for i in range(t):
	s = input()
	cnt = [0] * 3
	pos = [0] * 3
	for j in range(len(s)):
		if 'A' <= s[j] <= 'Z':
			cnt[0] += 1
			pos[0] = j
		elif 'a' <= s[j] <= 'z':
			cnt[1] += 1
			pos[1] = j
		else:
			cnt[2] += 1
			pos[2] = j
	if cnt[0] and cnt[1] and cnt[2]:
		print(s)
	else:
		s1 = list(s)
		for j in range(3):
			j1 = (j + 1) % 3
			j2 = (j + 2) % 3
			if not cnt[j] and cnt[j1] and cnt[j2]:
				if cnt[j1] > 1:
					s1[pos[j1]] = sym[j]
				else:
					s1[pos[j2]] = sym[j]
			if cnt[j] and (not cnt[j1]) and (not cnt[j2]):
				s1[0] = sym[j1]
				s1[1] = sym[j2]
		print(''.join(s1))


n = int(input())
s = str()
for u in range(n):
	s = input()
	l = []
	d = []
	u = []
	toreplace = []
	for i in range(len(s)):
		if s[i].isupper():
			u.append(i)
		elif s[i].islower():
			l.append(i)
		elif s[i].isdigit():
			d.append(i)
	if len(d) > 0:
		if len(u) > 0:
			if len(l) > 0:
				print(s)
				continue
	if len(d) == 0:
		toreplace.append('d')
	if len(l) == 0:
		toreplace.append('l')
	if len(u) == 0:
		toreplace.append('u')
	if len(toreplace) == 1:
		if len(d) == 0:
			if len(u) > 1:
				s = s[:u[0]] + '1' + s[u[0] + 1:]
			else:
				s = s[:l[0]] + '1' + s[l[0] + 1:]
		elif len(l) == 0:
			if len(u) > 1:
				s = s[:u[0]] + 'a' + s[u[0] + 1:]
			else:
				s = s[:d[0]] + 'a' + s[d[0] + 1:]
		elif len(u) == 0:
			if len(l) > 1:
				s = s[:l[0]] + 'A' + s[l[0] + 1:]
			else:
				s = s[:d[0]] + 'A' + s[d[0] + 1:]
		print(s)
		continue
	if len(d) > 0:
		print(s[:len(s) - 2] + 'a' + 'A')
	elif len(u) > 0:
		print(s[:len(s) - 2] + 'a' + '1')
	elif len(l) > 0:
		print(s[:len(s) - 2] + '1' + 'A')


import string

def solve(password):
	uppers = list((i for i in range(len(password)) if password[i] in string.ascii_uppercase))
	lowers = list((i for i in range(len(password)) if password[i] in string.ascii_lowercase))
	digits = list((i for i in range(len(password)) if password[i].isdigit()))
	l = list(password)
	if len(uppers) == 0 and len(lowers) == 0:
		(l[1], l[2]) = 'Aa'
	elif len(uppers) == 0 and len(digits) == 0:
		(l[1], l[2]) = 'A0'
	elif len(lowers) == 0 and len(digits) == 0:
		(l[1], l[2]) = 'a0'
	elif len(uppers) == 0:
		if len(digits) > 1:
			l[digits[0]] = 'A'
		else:
			l[lowers[0]] = 'A'
	elif len(lowers) == 0:
		if len(digits) > 1:
			l[digits[0]] = 'a'
		else:
			l[uppers[0]] = 'a'
	elif len(digits) == 0:
		if len(uppers) > 1:
			l[uppers[0]] = '0'
		else:
			l[lowers[0]] = '0'
	return ''.join(l)
print('\n'.join(list((solve(input()) for _ in range(int(input()))))))


for _ in range(int(input())):
	s = input()
	u = d = l = 0
	ui = li = di = None
	for i in range(len(s)):
		if 97 <= ord(s[i]) <= 122:
			l += 1
			li = i
		elif 65 <= ord(s[i]) <= 90:
			u += 1
			ui = i
		else:
			d += 1
			di = i
	if u == 0 and d == 0:
		s = 'A0' + s[2:]
	elif u == 0 and l == 0:
		s = 'Aa' + s[2:]
	elif l == 0 and d == 0:
		s = 'a0' + s[2:]
	elif u == 0:
		if d > l:
			s = s[:di] + 'A' + s[di + 1:]
		else:
			s = s[:li] + 'A' + s[li + 1:]
	elif d == 0:
		if u > l:
			s = s[:ui] + '0' + s[ui + 1:]
		else:
			s = s[:li] + '0' + s[li + 1:]
	elif l == 0:
		if u > d:
			s = s[:ui] + 'a' + s[ui + 1:]
		else:
			s = s[:di] + 'a' + s[di + 1:]
	print(s)


import re
import random

def check(strings):
	digit = re.sub('[^0-9]', '', strings)
	lower = re.sub('[^a-z]', '', strings)
	upper = re.sub('[^A-Z]', '', strings)
	while len(digit) == 0 or len(lower) == 0 or len(upper) == 0:
		if len(digit) > len(lower):
			if len(digit) > len(upper):
				p = '[0-9]'
				if len(lower) == 0:
					a = 0
					while a < len(strings):
						if re.match(p, strings[a]):
							strings = strings[0:a] + random.choice('abcdefghijklmnopqrstuvwxyz') + strings[a + 1:]
							lower = re.sub('[^a-z]', '', strings)
							break
						a += 1
				else:
					a = 0
					while a < len(strings):
						if re.match(p, strings[a]):
							strings = strings[0:a] + random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ') + strings[a + 1:]
							upper = re.sub('[^A-Z]', '', strings)
							break
						a += 1
			else:
				p = '[A-Z]'
				a = 0
				while a < len(strings):
					if re.match(p, strings[a]):
						strings = strings[0:a] + random.choice('abcdefghijklmnopqrstuvwxyz') + strings[a + 1:]
						lower = re.sub('[^a-z]', '', strings)
						break
					a += 1
		elif len(lower) > len(upper):
			p = '[a-z]'
			if len(digit) == 0:
				a = 0
				while a < len(strings):
					if re.match(p, strings[a]):
						strings = strings[0:a] + str(random.randint(0, 9)) + strings[a + 1:]
						digit = re.sub('[^0-9]', '', strings)
						break
					a += 1
			else:
				a = 0
				while a < len(strings):
					if re.match(p, strings[a]):
						strings = strings[0:a] + random.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZ') + strings[a + 1:]
						upper = re.sub('[^A-Z]', '', strings)
						break
					a += 1
		else:
			p = '[A-Z]'
			if len(digit) == 0:
				a = 0
				while a < len(strings):
					if re.match(p, strings[a]):
						strings = strings[0:a] + str(random.randint(0, 9)) + strings[a + 1:]
						digit = re.sub('[^0-9]', '', strings)
						break
					a += 1
			else:
				a = 0
				while a < len(strings):
					if re.match(p, strings[a]):
						strings = strings[0:a] + random.choice('abcdefghijklmnopqrstuvwxyz') + strings[a + 1:]
						lower = re.sub('[^a-z]', '', strings)
						break
					a += 1
	return strings
t = int(input())
l = list()
while t is not 0:
	string = str(input())
	l.append(string)
	t -= 1
for i in l:
	st = check(i)
	print(st)


T = int(input())
a = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}
b = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'}
c = {'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M'}
for i in range(T):
	numbers = 0
	bukvs = 0
	Gbukvs = 0
	s = input()
	new_s = s
	for elem in s:
		if elem in a:
			numbers += 1
		elif elem in b:
			bukvs += 1
		else:
			Gbukvs += 1
	if numbers == 0:
		if Gbukvs == max(Gbukvs, bukvs):
			for i in range(len(s)):
				if s[i] in c:
					new_s = s[:i] + '1' + s[i + 1:]
					Gbukvs -= 1
					break
		else:
			for i in range(len(s)):
				if s[i] in b:
					new_s = s[:i] + '1' + s[i + 1:]
					bukvs -= 1
					break
	s = new_s
	if bukvs == 0:
		if Gbukvs == max(Gbukvs, numbers):
			for i in range(len(s)):
				if s[i] in c:
					new_s = s[:i] + 'a' + s[i + 1:]
					Gbukvs -= 1
					break
		else:
			for i in range(len(s)):
				if s[i] in a:
					new_s = s[:i] + 'a' + s[i + 1:]
					numbers -= 1
					break
	s = new_s
	if Gbukvs == 0:
		if numbers == max(numbers, bukvs):
			for i in range(len(s)):
				if s[i] in a:
					new_s = s[:i] + 'A' + s[i + 1:]
					numbers -= 1
					break
		else:
			for i in range(len(s)):
				if s[i] in b:
					new_s = s[:i] + 'A' + s[i + 1:]
					bukvs -= 1
					break
	print(new_s)


import re

def replace(arr, fr, to):
	index = arr.index(fr)
	arr = arr[0:index] + to + arr[index + 1:]
	return arr
t = int(input())
for i in range(t):
	password = str(input().strip())
	lower = re.findall('[a-z]', password)
	upper = re.findall('[A-Z]', password)
	number = re.findall('[0-9]', password)
	l_len = len(lower)
	u_len = len(upper)
	n_len = len(number)
	if l_len == 0:
		if u_len >= 2:
			password = replace(password, upper[0], 'a')
			upper = upper[1:]
			u_len -= 1
		elif n_len >= 2:
			password = replace(password, number[0], 'a')
			number = number[1:]
			n_len -= 1
	if u_len == 0:
		if l_len >= 2:
			password = replace(password, lower[0], 'A')
			lower = lower[1:]
			l_len -= 1
		elif n_len >= 2:
			password = replace(password, number[0], 'A')
			number = number[1:]
			n_len -= 1
	if n_len == 0:
		if u_len >= 2:
			password = replace(password, upper[0], '1')
			upper = upper[1:]
			u_len -= 1
		elif l_len >= 2:
			password = replace(password, lower[0], '1')
			lower = lower[1:]
			l_len -= 1
	print(password)


n = int(input())
for x in range(n):
	u = 0
	l = 0
	d = 0
	p = list(input())
	for y in range(len(p)):
		if p[y].upper() == p[y].lower():
			d += 1
		elif p[y] == p[y].upper():
			u += 1
		else:
			l += 1
	if d > 0 and u > 0 and (l > 0):
		print(''.join(p))
	else:
		if d == 0 and l == 0:
			p[0] = 'a'
			p[1] = '5'
		elif d == 0 and u == 0:
			p[0] = 'G'
			p[1] = '5'
		elif u == 0 and l == 0:
			p[0] = 'a'
			p[1] = 'A'
		elif u == 0 and l >= d:
			if p[0] == p[0].lower() and p[0].upper() != p[0].lower():
				p[0] = 'A'
			else:
				p[1] = 'A'
		elif u == 0 and l < d:
			if p[0].upper() == p[0].lower():
				p[0] = 'A'
			else:
				p[1] = 'A'
		elif l == 0 and u >= d:
			if p[0] == p[0].upper() and p[0].upper() != p[0].lower():
				p[0] = 'a'
			else:
				p[1] = 'a'
		elif l == 0 and d > u:
			if p[0].upper() == p[0].lower():
				p[0] = 'a'
			else:
				p[1] = 'a'
		elif d == 0 and u >= l:
			if p[0] == p[0].upper():
				p[0] = '5'
			else:
				p[1] = '5'
		elif d == 0 and l > u:
			if p[0] == p[0].lower():
				p[0] = '5'
			else:
				p[1] = '5'
		print(''.join(p))


t = input()
for i in range(int(t)):
	s = input()
	flag = [0, 0, 0]
	for char in s:
		if char.islower():
			flag[0] = 1
		elif char.isupper():
			flag[1] = 1
		elif char.isdigit():
			flag[2] = 1
	if flag == [1, 1, 1]:
		print(s)
	elif flag == [0, 1, 1]:
		flag = [0, 0, 0]
		i = 0
		for char in s:
			if flag[1] == 1 and char.isupper():
				s = s[:i] + 'a' + s[i + 1:]
				break
			elif flag[2] == 1 and char.isdigit():
				s = s[:i] + 'a' + s[i + 1:]
				break
			if char.islower():
				flag[0] = 1
			elif char.isupper():
				flag[1] = 1
			elif char.isdigit():
				flag[2] = 1
			i += 1
		print(s)
	elif flag == [1, 0, 1]:
		flag = [0, 0, 0]
		i = 0
		for char in s:
			if flag[0] == 1 and char.islower():
				s = s[:i] + 'A' + s[i + 1:]
				break
			elif flag[2] == 1 and char.isdigit():
				s = s[:i] + 'A' + s[i + 1:]
				break
			if char.islower():
				flag[0] = 1
			elif char.isupper():
				flag[1] = 1
			elif char.isdigit():
				flag[2] = 1
			i += 1
		print(s)
	elif flag == [1, 1, 0]:
		flag = [0, 0, 0]
		i = 0
		for char in s:
			if flag[0] == 1 and char.islower():
				s = s[:i] + '1' + s[i + 1:]
				break
			elif flag[1] == 1 and char.isupper():
				s = s[:i] + '1' + s[i + 1:]
				break
			if char.islower():
				flag[0] = 1
			elif char.isupper():
				flag[1] = 1
			elif char.isdigit():
				flag[2] = 1
			i += 1
		print(s)
	elif flag == [1, 0, 0]:
		print('A1' + s[2:])
	elif flag == [0, 1, 0]:
		print('a1' + s[2:])
	elif flag == [0, 0, 1]:
		print('aA' + s[2:])


T = int(input())
for _ in range(T):
	s = input()
	countLower = 0
	countUpper = 0
	countDigits = 0
	for i in s:
		if i.islower():
			countLower += 1
		if i.isupper():
			countUpper += 1
		if i.isdigit():
			countDigits += 1
	if countLower == 0 or countUpper == 0 or countDigits == 0:
		result = list(s)
		fn = lambda x: x
		if countLower > 1:
			fn = str.islower
		if countUpper > 1:
			fn = str.isupper
		if countDigits > 1:
			fn = str.isdigit
		count = 0
		for i in [countLower, countUpper, countDigits]:
			if i == 0:
				count += 1
		if count == 1:
			ch = ''
			if countLower == 0:
				ch = 'i'
			if countUpper == 0:
				ch = 'I'
			if countDigits == 0:
				ch = '1'
			for i in range(len(s)):
				if fn(s[i]):
					result[i] = ch
					break
		else:
			ch1 = ''
			ch2 = ''
			ch3 = ''
			if countLower == 0:
				ch1 = 'i'
			if countUpper == 0:
				ch2 = 'I'
			if countDigits == 0:
				ch3 = '1'
			if ch1 == '':
				result[0] = ch2
				result[1] = ch3
			elif ch2 == '':
				result[0] = ch1
				result[1] = ch3
			else:
				result[0] = ch1
				result[1] = ch2
		print(''.join(result))
	else:
		print(s)


n = int(input())
for i in range(n):
	di = False
	didi = False
	up = False
	upup = False
	lo = False
	lolo = False
	s = input()
	for c in s:
		if 48 <= ord(c) <= 57:
			if di:
				didi = True
			di = True
		elif 65 <= ord(c) <= 90:
			if up:
				upup = True
			up = True
		elif 97 <= ord(c) <= 122:
			if lo:
				lolo = True
			lo = True
	if not di and (not up):
		print('0A' + s[2:])
	elif not up and (not lo):
		print('Aa' + s[2:])
	elif not lo and (not di):
		print('a0' + s[2:])
	elif not di:
		if lolo:
			for i in range(len(s)):
				if 97 <= ord(s[i]) <= 122:
					break
			print(s[:i] + '0' + s[i + 1:])
		else:
			for i in range(len(s)):
				if 65 <= ord(s[i]) <= 90:
					break
			print(s[:i] + '0' + s[i + 1:])
	elif not up:
		if lolo:
			for i in range(len(s)):
				if 97 <= ord(s[i]) <= 122:
					break
			print(s[:i] + 'A' + s[i + 1:])
		else:
			for i in range(len(s)):
				if 48 <= ord(s[i]) <= 57:
					break
			print(s[:i] + 'A' + s[i + 1:])
	elif not lo:
		if upup:
			for i in range(len(s)):
				if 65 <= ord(s[i]) <= 90:
					break
			print(s[:i] + 'a' + s[i + 1:])
		else:
			for i in range(len(s)):
				if 48 <= ord(s[i]) <= 57:
					break
			print(s[:i] + 'a' + s[i + 1:])
	else:
		print(s)


def main():
	n = int(input(''))
	lista = []
	minus = False
	mayuscula = False
	numero = False
	cambio = False
	cambio2 = False
	cambio3 = False
	anteriorEstado = []
	estado = []
	while n > 0:
		palabra = input('')
		lista = junto(palabra)
		wordlist = list(palabra)
		minus = lista[0]
		mayuscula = lista[1]
		numero = lista[2]
		palabra = calcular(minus, mayuscula, numero, wordlist, palabra)
		n -= 1
		print(palabra)

def calcular(minus, mayuscula, numero, wordlist, palabra):
	if minus and mayuscula and numero:
		return palabra
	if minus == False:
		cambio = False
		for x in range(len(wordlist)):
			anteriorEstado = junto(palabra)
			letra = wordlist[x]
			if cambio == False:
				wordlist[x] = 'a'
				palabra = ''.join(wordlist)
				estado = junto(palabra)
				cambio = True
			if estado[0] and estado[1] and estado[2]:
				return palabra
			if estado[2] == anteriorEstado[2] and estado[1] == anteriorEstado[1]:
				continue
			else:
				wordlist[x] = letra
				cambio = False
	if mayuscula == False:
		cambio2 = False
		for x in range(len(wordlist)):
			anteriorEstado = junto(palabra)
			letra = wordlist[x]
			if cambio2 == False:
				wordlist[x] = 'A'
				palabra = ''.join(wordlist)
				estado = junto(palabra)
				cambio2 = True
			if estado[0] and estado[1] and estado[2]:
				return palabra
			if estado[0] == anteriorEstado[0] and estado[2] == anteriorEstado[2]:
				continue
			else:
				wordlist[x] = letra
				cambio2 = False
	if numero == False:
		cambio3 = False
		for x in range(len(wordlist)):
			anteriorEstado = junto(palabra)
			letra = wordlist[x]
			if cambio3 == False:
				wordlist[x] = '1'
				palabra = ''.join(wordlist)
				estado = junto(palabra)
				cambio3 = True
			if estado[0] and estado[1] and estado[2]:
				return palabra
			if estado[0] == anteriorEstado[0] and estado[1] == anteriorEstado[1]:
				continue
			else:
				wordlist[x] = letra
				cambio3 = False

def junto(palabra):
	lis = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'ñ', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	lis2 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'Ñ', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
	lista = list(palabra)
	boo1 = False
	boo2 = False
	boo3 = False
	for x in range(len(lista)):
		if lista[x] in lis and boo1 == False:
			boo1 = True
		elif lista[x] in lis2 and boo2 == False:
			boo2 = True
		elif lista[x].isdigit() and boo3 == False:
			boo3 = True
		if boo1 and boo2 and boo3:
			return (boo1, boo2, boo3)
	return (boo1, boo2, boo3)
main()


upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lower = 'abcdefghijklmnopqrstuvwxyz'
digit = '0123456789'

def get_dict(pwd):
	d = {'upper': 0, 'lower': 0, 'digits': 0}
	pwd = list(pwd)
	for p in pwd:
		if p in upper:
			d['upper'] += 1
		elif p in lower:
			d['lower'] += 1
		elif p in digit:
			d['digits'] += 1
	return d

def get_pwd(pwd):
	dict = get_dict(pwd)
	if 0 not in dict.values():
		return pwd
	else:
		pwd = list(pwd)
		for (k, v) in dict.items():
			if v == 0:
				maxV = max(dict, key=lambda x: dict[x])
				dict[maxV] -= 1
				dict[k] += 1
				if maxV == 'lower':
					for i in range(len(pwd)):
						if pwd[i] in lower:
							if k == 'digits':
								pwd[i] = digit[0]
							elif k == 'upper':
								pwd[i] = upper[0]
							else:
								pwd[i] = lower[0]
							break
				elif maxV == 'upper':
					for i in range(len(pwd)):
						if pwd[i] in upper:
							if k == 'digits':
								pwd[i] = digit[0]
							elif k == 'upper':
								pwd[i] = upper[0]
							else:
								pwd[i] = lower[0]
							break
				else:
					for i in range(len(pwd)):
						if pwd[i] in digit:
							if k == 'digits':
								pwd[i] = digit[0]
							elif k == 'upper':
								pwd[i] = upper[0]
							else:
								pwd[i] = lower[0]
							break
		return ''.join(pwd)
n = int(input())
result = list()
for _ in range(n):
	s = input()
	result.append(get_pwd(s))
for r in result:
	print(r)


def password():
	lower = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
	number = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}
	upper = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}
	n = int(input())
	inputs = []
	for i in range(n):
		inputs.append(input())
	for temp in inputs:
		l = 0
		L = []
		nu = 0
		N = []
		u = 0
		U = []
		for j in range(len(temp)):
			if l > 0 and u > 0 and (nu > 0):
				break
			if temp[j] in lower:
				l += 1
				if l >= 2:
					L.append(j)
				continue
			if temp[j] in upper:
				u += 1
				if u >= 2:
					U.append(j)
				continue
			if temp[j] in number:
				nu += 1
				if nu >= 2:
					N.append(j)
				continue
		if l == 0:
			if len(U) != 0:
				temp = temp[:U[0]] + 'a' + temp[U[0] + 1:]
				U.remove(U[0])
			elif len(N) != 0:
				temp = temp[:N[0]] + 'a' + temp[N[0] + 1:]
				N.remove(N[0])
		if nu == 0:
			if len(U) != 0:
				temp = temp[:U[0]] + '1' + temp[U[0] + 1:]
				U.remove(U[0])
			elif len(L) != 0:
				temp = temp[:L[0]] + '1' + temp[L[0] + 1:]
				L.remove(L[0])
		if u == 0:
			if len(L) != 0:
				temp = temp[:L[0]] + 'A' + temp[L[0] + 1:]
				L.remove(L[0])
			elif len(N) != 0:
				temp = temp[:N[0]] + 'A' + temp[N[0] + 1:]
				N.remove(N[0])
		print(temp)
password()


import ctypes
t = int(input())
ans = []

def printf(s):
	print(''.join(s))
for i in range(t):
	s = list(input())
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	big = alpha.upper()
	a = 0
	b = 0
	n = 0
	fa = None
	fb = None
	fn = None
	for j in range(len(s)):
		if s[j] in alpha:
			if fa is None:
				fa = j
			a += 1
		elif s[j] in big:
			if fb is None:
				fb = j
			b += 1
		else:
			if fn is None:
				fn = j
			n += 1
	if a and b and n:
		printf(s)
	elif a and (not b) and (not n):
		printf(s[:-2] + ['A'] + ['1'])
	elif a and b and (not n):
		if a > b:
			s[fa] = '1'
		else:
			s[fb] = '1'
		printf(s)
	elif a and (not b) and n:
		if a > n:
			s[fa] = 'A'
		else:
			s[fn] = 'A'
		printf(s)
	elif not a and b and (not n):
		printf(s[:-2] + ['a'] + ['1'])
	elif not a and b and n:
		if b > n:
			s[fb] = 'a'
		else:
			s[fn] = 'a'
		printf(s)
	elif not a and (not b) and n:
		printf(s[:-2] + ['a'] + ['A'])


t = int(input())
while t:
	s = input()
	UpperCount = 0
	LowerCount = 0
	NumCount = 0
	Upper = []
	Lower = []
	Num = []
	l = len(s)
	for i in range(len(s)):
		if s[i].isupper():
			UpperCount = UpperCount + 1
			Upper.append(i)
		elif s[i].islower():
			LowerCount = LowerCount + 1
			Lower.append(i)
		else:
			NumCount = NumCount + 1
			Num.append(i)
	if UpperCount == 0 and LowerCount == 0:
		print('Aa' + s[2:])
	elif UpperCount == 0 and NumCount == 0:
		print('A1' + s[2:])
	elif NumCount == 0 and LowerCount == 0:
		print('1a' + s[2:])
	elif UpperCount == 0:
		if LowerCount > 1:
			print(s[:Lower[0]] + 'A' + s[Lower[0] + 1:])
		else:
			print(s[:Num[0]] + 'A' + s[Num[0] + 1:])
	elif LowerCount == 0:
		if UpperCount > 1:
			print(s[:Upper[0]] + 'a' + s[Upper[0] + 1:])
		else:
			print(s[:Num[0]] + 'a' + s[Num[0] + 1:])
	elif NumCount == 0:
		if LowerCount > 1:
			print(s[:Lower[0]] + '1' + s[Lower[0] + 1:])
		else:
			print(s[:Upper[0]] + '1' + s[Upper[0] + 1:])
	else:
		print(s)
	t -= 1


for _ in range(int(input())):
	s = input()
	lc = 0
	uc = 0
	nc = 0
	for j in range(len(s)):
		if s[j].islower():
			lc += 1
		elif s[j].isupper():
			uc += 1
		else:
			nc += 1
	k = 0
	l = 0
	if nc != 0 and lc != 0 and (uc != 0):
		print(s)
	elif nc + lc + uc == nc:
		s = s[:len(s) - 1] + 'a'
		s = s[:len(s) - 2] + 'A' + s[-1]
		print(s)
	elif lc + uc == 0:
		s = s[:len(s) - 1] + 'a'
		s = s[:len(s) - 2] + 'A' + s[-1]
		print(s)
	elif nc + uc == 0:
		s = s[:len(s) - 1] + '1'
		s = s[:len(s) - 2] + 'A' + s[-1]
		print(s)
	elif nc + lc == 0:
		s = s[:len(s) - 1] + '1'
		s = s[:len(s) - 2] + 'a' + s[-1]
		print(s)
	elif nc == 0:
		for i in range(len(s)):
			if ord('a') <= ord(s[i]) <= ord('z'):
				k += 1
			if ord('A') <= ord(s[i]) <= ord('Z'):
				l += 1
			if k > 1 or l > 1:
				s = s[:i] + '1' + s[i + 1:]
				print(s)
				break
	elif lc == 0:
		for i in range(len(s)):
			if ord('0') <= ord(s[i]) <= ord('9'):
				k += 1
			if ord('A') <= ord(s[i]) <= ord('Z'):
				l += 1
			if k > 1 or l > 1:
				s = s[:i] + 'a' + s[i + 1:]
				print(s)
				break
	elif uc == 0:
		for i in range(len(s)):
			if ord('a') <= ord(s[i]) <= ord('z'):
				k += 1
			if ord('0') <= ord(s[i]) <= ord('9'):
				l += 1
			if k > 1 or l > 1:
				s = s[:i] + 'A' + s[i + 1:]
				print(s)
				break


n = int(input())
B = [{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}, {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}, {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}]
for i in range(n):
	s = input()
	A = [0] * 3
	for i in range(len(s)):
		for j in range(3):
			if s[i] in B[j]:
				A[j] += 1
	if A[0] != 0 and A[1] != 0 and (A[2] != 0):
		print(s)
	else:
		for j1 in range(3):
			j2 = (j1 + 1) % 3
			j3 = (j1 + 2) % 3
			if A[j1] == 0 and A[j2] != 0 and (A[j3] != 0):
				if s[0] in B[j2] and A[j2] > 1 or (s[0] in B[j3] and A[j3] > 1):
					h = str(B[j1].pop())
					B[j1].add(h)
					print(h + s[1:])
					break
				else:
					h = str(B[j1].pop())
					B[j1].add(h)
					print(s[0] + str(h) + s[2:])
					break
			elif A[j1] == 0:
				h = str(B[j1].pop())
				B[j1].add(h)
				if A[j2] == 0:
					h1 = str(B[j2].pop())
					B[j2].add(h1)
					print(h + h1 + s[2:])
					break
				else:
					h1 = str(B[j3].pop())
					B[j3].add(h1)
					print(h + h1 + s[2:])
					break


for _ in range(int(input())):
	s = input()
	counta = 0
	countA = 0
	count1 = 0
	for j in range(len(s)):
		if ord('a') <= ord(s[j]) <= ord('z'):
			counta += 1
		elif ord('A') <= ord(s[j]) <= ord('Z'):
			countA += 1
		else:
			count1 += 1
	k = 0
	l = 0
	if count1 != 0 and counta != 0 and (countA != 0):
		print(s)
	elif count1 + counta + countA == count1:
		s = s[:len(s) - 1] + 'a'
		s = s[:len(s) - 2] + 'A' + s[-1]
		print(s)
	elif count1 + counta + countA == count1:
		s = s[:len(s) - 1] + 'a'
		s = s[:len(s) - 2] + 'A' + s[-1]
		print(s)
	elif count1 + counta + countA == counta:
		s = s[:len(s) - 1] + '1'
		s = s[:len(s) - 2] + 'A' + s[-1]
		print(s)
	elif count1 + counta + countA == countA:
		s = s[:len(s) - 1] + '1'
		s = s[:len(s) - 2] + 'a' + s[-1]
		print(s)
	elif count1 == 0:
		for i in range(len(s)):
			if ord('a') <= ord(s[i]) <= ord('z'):
				k += 1
			if ord('A') <= ord(s[i]) <= ord('Z'):
				l += 1
			if k > 1 or l > 1:
				s = s[:i] + '1' + s[i + 1:]
				print(s)
				break
	elif counta == 0:
		for i in range(len(s)):
			if ord('0') <= ord(s[i]) <= ord('9'):
				k += 1
			if ord('A') <= ord(s[i]) <= ord('Z'):
				l += 1
			if k > 1 or l > 1:
				s = s[:i] + 'a' + s[i + 1:]
				print(s)
				break
	elif countA == 0:
		for i in range(len(s)):
			if ord('a') <= ord(s[i]) <= ord('z'):
				k += 1
			if ord('0') <= ord(s[i]) <= ord('9'):
				l += 1
			if k > 1 or l > 1:
				s = s[:i] + 'A' + s[i + 1:]
				print(s)
				break


low = ''
for i in range(97, 97 + 26, 1):
	low += chr(i)
up = ''
for i in range(65, 65 + 26):
	up += chr(i)
dig = ''
for i in range(48, 49 + 9):
	dig += chr(i)
r = input
n = int(r())
res = ''
for i in range(n):
	rs = str(r())
	s = [x.strip() for x in rs]
	(fl, ll, fu, lu, fd, ld) = (-1, -1, -1, -1, -1, -1)
	cnt = 0
	res = ''
	for c in s:
		if c in low:
			if fl == -1:
				fl = cnt
				ll = cnt
			else:
				ll = cnt
		elif c in up:
			if fu == -1:
				fu = cnt
				lu = cnt
			else:
				lu = cnt
		if c in dig:
			if fd == -1:
				fd = cnt
				ld = cnt
			else:
				ld = cnt
		cnt += 1
	if fl != -1 and fu != -1 and (fd != -1):
		for i in s:
			res += i
		print(res)
	else:
		if fl == -1 and fu == -1:
			s[fd] = 'a'
			s[fd + 1] = 'A'
		elif fu == -1 and fd == -1:
			s[fl] = 'A'
			s[fl + 1] = '1'
		elif fl == -1 and fd == -1:
			s[fu] = 'a'
			s[fu + 1] = '1'
		elif fl != -1 and fu != -1:
			if fl != ll:
				s[fl] = '1'
			else:
				s[fu] = '1'
		elif fu != -1 and fd != -1:
			if fu != lu:
				s[fu] = 'a'
			else:
				s[fd] = 'a'
		elif fl != -1 and fd != -1:
			if fl != ll:
				s[fl] = 'A'
			else:
				s[fd] = 'A'
		for i in s:
			res += i
		print(res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
for _ in range(int(input())):
	string = input()
	n = len(string)
	check = [0, 0, 0]
	exchange = ['a', 'A', '1']
	flag = 'dont'
	for i in string:
		if i.isdigit():
			check[2] += 1
		elif i.islower():
			check[0] += 1
		else:
			check[1] += 1
	if 0 not in check:
		print(string)
	else:
		by = check.index(0)
		for i in range(n):
			ans = string[:i] + exchange[by] + string[i + 1:]
			checker = [0, 0, 0]
			for i in ans:
				if i.isdigit():
					checker[2] += 1
				elif i.islower():
					checker[0] += 1
				else:
					checker[1] += 1
			if 0 not in checker:
				print(ans)
				flag = 'stop'
				break
	if flag == 'dont':
		if string.isalpha():
			if string.islower():
				print('A4', end='')
				print(string[2:])
			elif string.isupper():
				print('a1', end='')
				print(string[2:])
		elif string.isdigit():
			print('aA', end='')
			print(string[2:])


import sys
sys.setrecursionlimit(int(10000000.0))

def solve(s):
	n = len(s)
	a = next((i for i in range(n) if s[i].isdigit()), -1)
	b = next((i for i in range(n) if s[i].islower()), -1)
	c = next((i for i in range(n) if s[i].isupper()), -1)
	if min(a, b, c) >= 0:
		return s
	ans = [x for x in s]
	for i in range(n):
		if i == a or i == b or i == c:
			continue
		if a == -1:
			ans[i] = '0'
			a = i
		elif b == -1:
			ans[i] = 'a'
			b = i
		elif c == -1:
			ans[i] = 'A'
			c = i
		else:
			break
	return ''.join(ans)

def main():
	ntc = int(input())
	for tc in range(ntc):
		s = input()
		ans = solve(s)
		print(ans)
main()


import random
import string
N = int(input(''))
L = []
for i in range(N):
	mdp = str(input(''))
	L.append(mdp)
F = []
for i in L:
	C = list(i)
	m = 0
	M = 0
	d = 0
	for j in range(len(C)):
		if 'a' <= C[j] <= 'z':
			m += 1
		if '0' <= C[j] <= '9':
			d += 1
		if 'A' <= C[j] <= 'Z':
			M += 1
	if m == 0:
		if d > 1:
			for j in range(len(C)):
				if '0' <= C[j] <= '9':
					C[j] = random.choice(string.ascii_lowercase)
					break
		elif M > 1:
			for j in range(len(C)):
				if 'A' <= C[j] <= 'Z':
					C[j] = random.choice(string.ascii_lowercase)
					break
	if d == 0:
		if m > 1:
			for j in range(len(C)):
				if 'a' <= C[j] <= 'z':
					C[j] = str(random.randint(0, 9))
					break
		elif M > 1:
			for j in range(len(C)):
				if 'A' <= C[j] <= 'Z':
					C[j] = str(random.randint(0, 9))
					break
	if M == 0:
		if m > 1:
			for j in range(len(C)):
				if 'a' <= C[j] <= 'z':
					C[j] = random.choice(string.ascii_uppercase)
					break
		elif d > 1:
			for j in range(len(C)):
				if '0' <= C[j] <= '9':
					C[j] = random.choice(string.ascii_uppercase)
					break
	F.append(''.join(C))
for i in F:
	print(i)


import sys
T = int(sys.stdin.readline())

def getSecurePassword(s):
	digits = 0
	lastDigitPos = [-1, -1]
	lChars = 0
	lastLPos = [-1, -1]
	uChars = 0
	lastUPos = [-1, -1]
	for i in range(len(s)):
		ch = s[i]
		if ch >= 'a' and ch <= 'z':
			lChars += 1
			lastLPos[1] = lastLPos[0]
			lastLPos[0] = i
		elif ch >= '0' and ch <= '9':
			digits += 1
			lastDigitPos[1] = lastDigitPos[0]
			lastDigitPos[0] = i
		elif ch >= 'A' and ch <= 'Z':
			uChars += 1
			lastUPos[1] = lastUPos[0]
			lastUPos[0] = i
	if uChars > 0 and lChars > 0 and (digits > 0):
		return s
	else:
		password = list(s)
		need = ''
		if lChars == 0:
			need = need + 'a'
		if uChars == 0:
			need = need + 'A'
		if digits == 0:
			need = need + '7'
		freePositions = []
		if lChars > 1:
			freePositions.append(lastLPos[0])
			if lChars > 2:
				freePositions.append(lastLPos[1])
		if uChars > 1:
			freePositions.append(lastUPos[0])
			if uChars > 2:
				freePositions.append(lastUPos[1])
		if digits > 1:
			freePositions.append(lastDigitPos[0])
			if digits > 2:
				freePositions.append(lastDigitPos[1])
		pos = 0
		while pos < len(need):
			password[freePositions[pos]] = need[pos]
			pos += 1
		return ''.join(password)
for inp in range(T):
	s = sys.stdin.readline().strip()
	print(getSecurePassword(s))


lower = [chr(i) for i in range(ord('a'), ord('a') + 26)]
upper = [chr(i) for i in range(ord('A'), ord('A') + 26)]
digit = [str(i) for i in range(10)]
t = int(input())
for i in range(t):
	s = list(input())
	flag = [0] * 3
	for c in s:
		if c in lower:
			flag[0] += True
		elif c in upper:
			flag[1] += True
		else:
			flag[2] += True
	cnt = flag.count(0)
	if cnt == 1:
		fr = [lower, upper, digit][flag.index(max(flag))]
		to = [lower, upper, digit][flag.index(min(flag))]
		for i in range(len(s)):
			if s[i] in fr:
				s[i] = to[0]
				break
	elif cnt == 2:
		aaa = []
		for (iii, jjj) in enumerate(flag):
			if jjj == 0:
				aaa.append(iii)
		s[0] = [lower, upper, digit][aaa[0]][0]
		s[1] = [lower, upper, digit][aaa[1]][0]
	print(''.join(s))


n = int(input())
for iter in range(n):
	s = input()
	(low, high, dig) = (0, 0, 0)
	(lowi, highi, digi) = (-1, -1, -1)
	(unlowi, unhighi, undigi) = (-1, -1, -1)
	for (i, c) in enumerate(s):
		if c.upper() != c:
			low += 1
			lowi = i
		if c.lower() != c:
			high += 1
			highi = i
		if c.isdigit():
			dig += 1
			digi = i
	if low > 0 and high > 0 and (dig > 0):
		print(s)
	elif low == 0 and high == 0:
		print('aA' + s[2:])
	elif low == 0 and dig == 0:
		print('a1' + s[2:])
	elif high == 0 and dig == 0:
		print('A1' + s[2:])
	elif low == 0:
		if high > 1:
			print(s[:highi] + 'a' + s[highi + 1:])
		else:
			print(s[:digi] + 'a' + s[digi + 1:])
	elif high == 0:
		if low > 1:
			print(s[:lowi] + 'A' + s[lowi + 1:])
		else:
			print(s[:digi] + 'A' + s[digi + 1:])
	elif dig == 0:
		if high > 1:
			print(s[:highi] + '1' + s[highi + 1:])
		else:
			print(s[:lowi] + '1' + s[lowi + 1:])


TT = int(input())
for TTT in range(TT):
	s = list(input())
	CL = -1
	L = -1
	D = -1
	for i in range(len(s)):
		if 'A' <= s[i] and s[i] <= 'Z':
			CL = i
		if 'a' <= s[i] and s[i] <= 'z':
			L = i
		if '0' <= s[i] and s[i] <= '9':
			D = i
	if D == -1:
		for i in range(len(s)):
			if i != L and i != CL:
				break
		D = i
		s[i] = '0'
	if L == -1:
		for i in range(len(s)):
			if i != CL and i != D:
				break
		L = i
		s[i] = 'z'
	if CL == -1:
		for i in range(len(s)):
			if i != L and i != D:
				break
		s[i] = 'A'
	print(''.join(s))


t = int(input())
for i in range(t):
	str = list(input())
	l = len(str)
	ul = 0
	ll = 0
	num = 0
	for j in range(l):
		if str[j] >= '0' and str[j] <= '9':
			num = num + 1
			pnum = j
		if str[j] >= 'A' and str[j] <= 'Z':
			ul = ul + 1
			pul = j
		if str[j] >= 'a' and str[j] <= 'z':
			ll = ll + 1
			pll = j
	if ul > 0 and ll > 0 and (num > 0):
		print(''.join(str))
		continue
	if ll == 0 and num == 0:
		str[0] = '1'
		str[1] = 'a'
		print(''.join(str))
		continue
	if ul == 0 and num == 0:
		str[0] = '1'
		str[1] = 'A'
		print(''.join(str))
		continue
	if ll == 0 and ul == 0:
		str[0] = 'A'
		str[1] = 'a'
		print(''.join(str))
		continue
	if ll > 0 and num > 0:
		if ll > 1:
			str[pll] = 'A'
		else:
			str[pnum] = 'A'
		print(''.join(str))
		continue
	if ul > 0 and num > 0:
		if ul > 1:
			str[pul] = 'a'
		else:
			str[pnum] = 'a'
		print(''.join(str))
		continue
	if ll > 0 and ul > 0:
		if ll > 1:
			str[pll] = '1'
		else:
			str[pul] = '1'
		print(''.join(str))
		continue


def ok(s):
	low = big = nr = False
	for x in s:
		if 'a' <= x <= 'z':
			low = True
		if 'A' <= x <= 'Z':
			big = True
		if '0' <= x <= '9':
			nr = True
	return (low, big, nr)
n = int(input())
for k in range(0, n):
	t = input()
	(low, big, nr) = ok(t)
	if low and big and nr:
		print(t)
		continue
	p = ''
	if not low:
		p = p + 'a'
	if not big:
		p = p + 'A'
	if not nr:
		p = p + '0'
	kk = False
	for i in range(0, len(t) - len(p) + 1):
		s = ''
		if i >= 1:
			s = t[0:i]
		s = s + p
		s = s + t[i + len(p):]
		(l, b, n) = ok(s)
		if l and b and n:
			print(s)
			kk = True
		if kk:
			break


import sys

def rint():
	return map(int, sys.stdin.readline().split())
T = int(input())
type_char = ['a', 'A', '1']
for i in range(T):
	s = list(input())
	t = []
	for c in s:
		if c.islower():
			t.append(0)
		elif c.isupper():
			t.append(1)
		else:
			t.append(2)
	none_type = []
	for j in range(3):
		if not j in t:
			none_type.append(j)
	if len(none_type) == 1:
		for j in range(len(s)):
			if t.count(t[j]) >= 2:
				s[j] = type_char[none_type[0]]
				break
	elif len(none_type) == 2:
		s[0] = type_char[none_type[0]]
		s[1] = type_char[none_type[1]]
	print(''.join(s))


import sys

def has_digit(s):
	ok = False
	for c in s:
		ok |= c.isdigit()
	return ok

def has_lower_alpha(s):
	ok = False
	for c in s:
		ok |= c.isalpha() & c.islower()
	return ok

def has_upper_alpha(s):
	ok = False
	for c in s:
		ok |= c.isalpha() & c.isupper()
	return ok

def gen(n):
	if n == 1:
		return ('1', 'a', 'A')
	if n == 2:
		return ('1a', '1A', 'aA')
	if n == 3:
		return '1aA'

def main():
	T = int(input())
	l = -1
	r = -1
	for _ in range(T):
		s = list(input())
		if has_digit(s) and has_lower_alpha(s) and has_upper_alpha(s):
			print(*s, sep='')
		else:
			ok = False
			for l in range(1, 3 + 1):
				for i in range(len(s)):
					ss = s.copy()
					for t in gen(l):
						ss[i:i + l] = t
						if has_digit(ss) and has_lower_alpha(ss) and has_upper_alpha(ss):
							print(*ss, sep='')
							ok = True
							break
					if ok:
						break
				if ok:
					break
main()


T = int(input())
while T > 0:
	T -= 1
	s = input()
	upc = 0
	upci = -1
	lwc = 0
	lwci = -1
	dig = 0
	digi = -1
	i = 0
	s = ' ' + s + ' '
	for letter in s:
		if letter >= 'A' and letter <= 'Z':
			upc += 1
			upci = i
		elif letter >= 'a' and letter <= 'z':
			lwc += 1
			lwci = i
		elif letter != ' ':
			dig += 1
			digi = i
		i += 1
	if (upc > 0) + (lwc > 0) + (dig > 0) == 0:
		pass
	elif (upc > 0) + (lwc > 0) + (dig > 0) == 1:
		if upc > 0:
			s = 'a' + '1' + s[3:]
		elif lwc > 0:
			s = 'A' + '1' + s[3:]
		elif dig > 0:
			s = 'A' + 'a' + s[3:]
		s = ' ' + s
	elif (upc > 0) + (lwc > 0) + (dig > 0) == 2:
		if upc > 1 and dig == 0:
			s = s[0:upci] + '1' + s[upci + 1:]
		elif upc > 1 and lwc == 0:
			s = s[0:upci] + 'a' + s[upci + 1:]
		elif lwc > 1 and upc == 0:
			s = s[0:lwci] + 'A' + s[lwci + 1:]
		elif lwc > 1 and dig == 0:
			s = s[0:lwci] + '1' + s[lwci + 1:]
		elif dig > 1 and lwc == 0:
			s = s[0:digi] + 'a' + s[digi + 1:]
		elif dig > 1 and upc == 0:
			s = s[0:digi] + 'A' + s[digi + 1:]
	else:
		pass
	print(s[1:])


from sys import stdin, stdout
T = int(stdin.readline())
for t in range(T):
	s = stdin.readline().strip()
	test = 'qazxswedcvfrtgbnhyujmkiolp'
	f = list(s)
	for i in range(len(f)):
		if f[i] in test:
			f[i] = 'a'
	add = []
	for c in test:
		if c in s:
			break
	else:
		add.append('a')
	test = test.upper()
	for i in range(len(f)):
		if f[i] in test:
			f[i] = 'A'
	for c in test:
		if c in s:
			break
	else:
		add.append('A')
	for i in range(10):
		if str(i) in s:
			break
	else:
		add.append('0')
	for i in range(len(f)):
		if '9' >= f[i] >= '0':
			f[i] = '0'
	s = list(s)
	for i in range(len(f)):
		if not add:
			break
		if f[i + 1:].count(f[i]):
			s[i] = add.pop()
	stdout.write(''.join(s) + '\n')


n = int(input())
for i in range(n):
	inp = input()
	lmin = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
	lmaj = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
	digits = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
	nmin = 0
	nmaj = 0
	ndig = 0
	for k in inp:
		if k in lmin:
			nmin += 1
		elif k in lmaj:
			nmaj += 1
		else:
			ndig += 1
	if nmin > 0 and nmaj > 0 and (ndig > 0):
		print(inp)
	elif nmin == 0 and nmaj == 0 and (ndig > 0):
		print('aA' + inp[2:])
	elif nmin > 0 and nmaj == 0 and (ndig == 0):
		print('A1' + inp[2:])
	elif nmin == 0 and nmaj > 0 and (ndig == 0):
		print('a1' + inp[2:])
	elif nmin == 0 and nmaj > 1 and (ndig > 1):
		print('a' + inp[1:])
	elif nmin > 1 and nmaj == 0 and (ndig > 1):
		print('A' + inp[1:])
	elif nmin > 1 and nmaj > 1 and (ndig == 0):
		print('1' + inp[1:])
	elif nmin == 0 and nmaj == 1:
		if inp[0] in lmaj:
			print(inp[:-1] + 'a')
		else:
			print('a' + inp[1:])
	elif nmin == 0 and ndig == 1:
		if inp[0] in digits:
			print(inp[:-1] + 'a')
		else:
			print('a' + inp[1:])
	elif nmaj == 0 and nmin == 1:
		if inp[0] in lmin:
			print(inp[:-1] + 'A')
		else:
			print('A' + inp[1:])
	elif nmaj == 0 and ndig == 1:
		if inp[0] in digits:
			print(inp[:-1] + 'A')
		else:
			print('A' + inp[1:])
	elif ndig == 0 and nmin == 1:
		if inp[0] in lmin:
			print(inp[:-1] + '1')
		else:
			print('1' + inp[1:])
	elif ndig == 0 and nmaj == 1:
		if inp[0] in lmaj:
			print(inp[:-1] + '1')
		else:
			print('1' + inp[1:])


t = int(input())
for test in range(t):
	s = input()
	lower = ''
	upper = ''
	digit = ''
	for i in range(len(s)):
		if s[i].isdigit():
			digit += str(i)
		elif s[i].isupper():
			upper += str(i)
		else:
			lower += str(i)
	if len(digit) and len(upper) and len(lower):
		print(s)
	elif len(digit) and len(upper) or (len(upper) and len(lower)) or (len(digit) and len(lower)):
		if len(lower) > 1:
			if len(digit) == 0:
				s = s[:int(lower[0])] + '1' + s[int(lower[0]) + 1:]
			else:
				s = s[:int(lower[0])] + 'A' + s[int(lower[0]) + 1:]
		elif len(upper) > 1:
			if len(digit) == 0:
				s = s[:int(upper[0])] + '1' + s[int(upper[0]) + 1:]
			else:
				s = s[:int(upper[0])] + 'a' + s[int(upper[0]) + 1:]
		elif len(digit) > 1:
			if len(lower) == 0:
				s = s[:int(digit[0])] + 'a' + s[int(digit[0]) + 1:]
			else:
				s = s[:int(digit[0])] + 'A' + s[int(digit[0]) + 1:]
		print(s)
	else:
		if len(digit) > 1:
			s = s[:int(digit[0])] + 'a' + s[int(digit[0]) + 1:]
			s = s[:int(digit[1])] + 'A' + s[int(digit[1]) + 1:]
		elif len(upper) > 1:
			s = s[:int(upper[0])] + '1' + s[int(upper[0]) + 1:]
			s = s[:int(upper[1])] + 'a' + s[int(upper[1]) + 1:]
		else:
			s = s[:int(lower[0])] + '1' + s[int(lower[0]) + 1:]
			s = s[:int(lower[1])] + 'A' + s[int(lower[1]) + 1:]
		print(s)


def get_counts(strng):
	counts = [0, 0, 0]
	lngth = len(strng)
	for i in range(lngth):
		cur_val = ord(strng[i])
		if cur_val >= 65 and cur_val <= 90:
			counts[1] += 1
		elif cur_val >= 97 and cur_val <= 122:
			counts[0] += 1
		elif cur_val >= 48 and cur_val <= 57:
			counts[2] += 1
	return counts

def correct_pass(strng):
	counts = get_counts(strng)
	n = len(strng)
	if counts[0] == 0:
		for i in range(n):
			cur_val = ord(strng[i])
			if cur_val >= 65 and cur_val <= 90 and (counts[1] > 1):
				strng[i] = 'a'
				counts[0] = 1
				counts[1] -= 1
				break
			if cur_val >= 48 and cur_val <= 57 and (counts[2] > 1):
				strng[i] = 'a'
				counts[0] = 1
				counts[2] -= 1
				break
	if counts[1] == 0:
		for i in range(n):
			cur_val = ord(strng[i])
			if cur_val >= 97 and cur_val <= 122 and (counts[0] > 1):
				strng[i] = 'A'
				counts[1] = 1
				counts[0] -= 1
				break
			if cur_val >= 48 and cur_val <= 57 and (counts[2] > 1):
				strng[i] = 'A'
				counts[1] = 1
				counts[2] -= 1
				break
	if counts[2] == 0:
		for i in range(n):
			cur_val = ord(strng[i])
			if cur_val >= 97 and cur_val <= 122 and (counts[0] > 1):
				strng[i] = '1'
				counts[2] = 1
				counts[0] -= 1
				break
			if cur_val >= 65 and cur_val <= 90 and (counts[1] > 1):
				strng[i] = '1'
				counts[2] = 1
				counts[1] -= 1
				break
	return strng
n = int(input())
strs = []
for i in range(n):
	strs.append(list(input()))
results = []
for i in range(n):
	print(''.join(correct_pass(strs[i])))


t = int(input())
for i in range(t):
	s = input()
	l = []
	u = []
	d = []
	for j in range(len(s)):
		if ord(s[j]) < ord('A'):
			d.append(j)
		elif ord(s[j]) < ord('a'):
			u.append(j)
		else:
			l.append(j)
	if len(d) > 0 and len(u) > 0 and (len(l) > 0):
		print(s)
	else:
		if len(d) == 0:
			if len(u) > 1:
				s = s[:u[-1]] + '1' + s[u[-1] + 1:]
				del u[-1]
			elif len(l) > 1:
				s = s[:l[-1]] + '1' + s[l[-1] + 1:]
				del l[-1]
		if len(u) == 0:
			if len(d) > 1:
				s = s[:d[-1]] + 'A' + s[d[-1] + 1:]
				del d[-1]
			elif len(l) > 1:
				s = s[:l[-1]] + 'A' + s[l[-1] + 1:]
				del l[-1]
		if len(l) == 0:
			if len(d) > 1:
				s = s[:d[-1]] + 'a' + s[d[-1] + 1:]
				del d[-1]
			elif len(u) > 1:
				s = s[:u[-1]] + 'a' + s[u[-1] + 1:]
				del u[-1]
		print(s)


import string
(t,) = map(int, input().split())

def invalid(s):
	minus = len(list(filter(lambda x: x in string.ascii_lowercase, s)))
	mayus = len(list(filter(lambda x: x in string.ascii_uppercase, s)))
	digits = len(list(filter(lambda x: x in string.digits, s)))
	return any((minus == 0, mayus == 0, digits == 0))

def gen_str(s):
	minus = len(list(filter(lambda x: x in string.ascii_lowercase, s)))
	mayus = len(list(filter(lambda x: x in string.ascii_uppercase, s)))
	digits = len(list(filter(lambda x: x in string.digits, s)))
	result = ''
	if minus == 0:
		result += 'a'
	if mayus == 0:
		result += 'A'
	if digits == 0:
		result += '0'
	return result
for _ in range(t):
	s = input()
	new_s = s
	if invalid(s):
		t = gen_str(s)
		new_s = t + s[len(t):]
		if invalid(new_s):
			new_s = s[:-len(t)] + t
	print(new_s)


for i in range(int(input())):
	s = list(input())
	mF = ''
	(c1, cntB, cntS) = (0, 0, 0)
	(l, u, c, k, stri, max) = (0, 0, 0, 0, 0, 0)
	for j in range(len(s)):
		if s[j] == '0' or s[j] == '1' or s[j] == '2' or (s[j] == '3') or (s[j] == '4') or (s[j] == '5') or (s[j] == '6') or (s[j] == '7') or (s[j] == '7') or (s[j] == '8') or (s[j] == '9'):
			c1 += 1
			l += 1
			if max < cntB:
				max = cntB
				mF = 'B'
				stri = j - cntB
			if max < cntS:
				mF = 's'
				max = cntS
				stri = j - cntS
			(cntB, cntS) = (0, 0)
		elif s[j].islower():
			u += 1
			cntS += 1
			if max < cntB:
				mF = 'B'
				max = cntB
				stri = j - cntB
			if max < c1:
				max = c1
				mF = '1'
				stri = j - c1
			(cntB, c1) = (0, 0)
		else:
			c += 1
			cntB += 1
			if max < cntS:
				max = cntS
				mF = 's'
				stri = j - cntS
			if max < c1:
				mF = '1'
				max = c1
				stri = j - c1
			(cntS, c1) = (0, 0)
	if max < cntS:
		max = cntS
		stri = len(s) - cntS
	if max < c1:
		max = c1
		stri = len(s) - c1
	if max < cntB:
		max = cntB
		stri = len(s) - cntB
	if l == 0 or u == 0 or c == 0:
		sd = 0
		if l == 0:
			s[stri] = '1'
			sd += 1
		if u == 0:
			s[stri + sd] = 'a'
			sd += 1
		if c == 0:
			s[stri + sd] = 'A'
	print(''.join(s))


import string
n = int(input())

def chr2id(c):
	if c in string.ascii_uppercase:
		return 1
	if c in string.digits:
		return 2
	return 0
repl = ['a', 'A', '1']
for _ in range(n):
	s = input()
	arr = [0] * len(s)
	chr_ids = [0] * len(s)
	last_n = [0] * 3
	id_counts = [0] * 3
	last_id = chr2id(s[0])
	id_counts[last_id] = 1
	chr_ids[0] = last_id
	for (i, c) in enumerate(s[1:]):
		c_id = chr2id(c)
		chr_ids[i + 1] = c_id
		id_counts[c_id] += 1
		if last_id == c_id:
			arr[i + 1] = arr[i] + 1
			if arr[i + 1] < len(last_n):
				last_n[arr[i + 1]] = i + 1
			else:
				last_n.append(i + 1)
		last_id = c_id
	change_count = sum(map(lambda x: x == 0, id_counts))
	if change_count == 0:
		print(s)
		continue
	l = change_count
	while last_n[l] == 0 and l > 0:
		l -= 1
	i = last_n[l]
	if l == 0:
		left = 0
		right = 0
		for (i, c) in enumerate(chr_ids):
			if chr_ids[left] == chr_ids[i] and id_counts[c] > change_count:
				right = i
			else:
				left = right = i
			if right - left >= change_count:
				break
		i = right
	i += 1
	c = 0
	s = list(s)
	for j in range(i - change_count, i):
		while id_counts[c] > 0:
			c += 1
		s[j] = repl[c]
		c += 1
	print(''.join(s))


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, **kwargs, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
for i in range(N):
	x = input()
	g = [0 for _ in range(len(x))]
	t = [0, 0, 0]
	r = ['0', 'a', 'A']
	for j in range(len(x)):
		y = x[j]
		if 'a' <= y <= 'z':
			g[j] = 1
		elif 'A' <= y <= 'Z':
			g[j] = 2
		t[g[j]] += 1
	if 0 not in t:
		print(x)
		continue
	ac = 0
	for d in t:
		if not d:
			ac += 1
	if ac == 1:
		for j in range(3):
			if t[j] == 0:
				c = r[j]
		for j in range(len(x)):
			if t[g[j]] > 1:
				print(x[:j] + c + x[j + 1:])
				break
		continue
	c = ''
	for j in range(3):
		if t[j] == 0:
			c = c + r[j]
	print(c + x[2:])


n = int(input())
for i in range(n):
	s = input()
	bm = 0
	bb = 0
	c = 0
	for j in s:
		if ord(j) >= 65 and ord(j) <= 90:
			bb += 1
		elif ord(j) >= 97 and ord(j) <= 122:
			bm += 1
		elif ord(j) >= 48 and ord(j) <= 57:
			c += 1
	for j in s:
		if not bb:
			if bm > 1 and (ord(j) >= 97 and ord(j) <= 122):
				print('A', end='')
				bb = 1
				bm -= 1
				continue
			if c > 1 and (ord(j) >= 48 and ord(j) <= 57):
				print('A', end='')
				bb = 1
				c -= 1
				continue
		if not bm:
			if bb > 1 and (ord(j) >= 65 and ord(j) <= 90):
				print('a', end='')
				bm = 1
				bb -= 1
				continue
			if c > 1 and (ord(j) >= 48 and ord(j) <= 57):
				print('a', end='')
				bm = 1
				c -= 1
				continue
		if not c:
			if bb > 1 and (ord(j) >= 65 and ord(j) <= 90):
				print('0', end='')
				c = 1
				bb -= 1
				continue
			if bm > 1 and (ord(j) >= 97 and ord(j) <= 122):
				print('0', end='')
				c = 1
				bm -= 1
				continue
		print(j, end='')
	print()


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007

def check(s):
	res = [0, 0, 0]
	for i in s:
		if i.islower():
			res[0] = 1
		elif i.isupper():
			res[1] = 1
		else:
			res[2] = 1
		if sum(res) == 3:
			return [True]
	return [False, res]
tc = ii1()
for _ in range(tc):
	s = is1()
	chk = check(s)
	if chk[0]:
		print(s)
	else:
		s1 = ''
		for i in range(3):
			if i == 0 and (not chk[1][i]):
				s1 += 'a'
			elif i == 1 and (not chk[1][i]):
				s1 += 'A'
			elif i == 2 and (not chk[1][i]):
				s1 += '1'
		for i in range(len(s) - len(s1) + 1):
			t = s[:i] + s1 + s[i + len(s1):]
			if check(t)[0]:
				print(t)
				break


T = int(input())
for i in range(0, T):
	s = input()
	s = list(s)
	sm = 0
	lr = 0
	di = 0
	for j in range(0, len(s)):
		if ord(s[j]) >= 48 and ord(s[j]) <= 57:
			di = di + 1
		if ord(s[j]) >= 65 and ord(s[j]) <= 90:
			lr = lr + 1
		if ord(s[j]) >= 97 and ord(s[j]) <= 122:
			sm = sm + 1
	if sm == 0 and lr == 0:
		s[0] = 'a'
		s[1] = 'A'
	elif sm == 0 and di == 0:
		s[0] = 'a'
		s[1] = '1'
	elif di == 0 and lr == 0:
		s[0] = 'A'
		s[1] = '1'
	elif sm == 0 and lr != 0 and (di != 0):
		if di == 1 and lr > 1:
			for j in range(0, len(s)):
				if ord(s[j]) >= 65 and ord(s[j]) <= 90:
					s[j] = 'a'
					break
		elif di > 1:
			for j in range(0, len(s)):
				if ord(s[j]) >= 48 and ord(s[j]) <= 57:
					s[j] = 'a'
					break
	elif sm != 0 and lr == 0 and (di != 0):
		if sm == 1 and di > 1:
			for j in range(0, len(s)):
				if ord(s[j]) >= 48 and ord(s[j]) <= 57:
					s[j] = 'A'
					break
		elif sm > 1:
			for j in range(0, len(s)):
				if ord(s[j]) >= 97 and ord(s[j]) <= 122:
					s[j] = 'A'
					break
	elif sm != 0 and lr != 0 and (di == 0):
		if sm == 1 and lr > 1:
			for j in range(0, len(s)):
				if ord(s[j]) >= 65 and ord(s[j]) <= 90:
					s[j] = '1'
					break
		elif sm > 1:
			for j in range(0, len(s)):
				if ord(s[j]) >= 97 and ord(s[j]) <= 122:
					s[j] = '1'
					break
	elif sm != 0 and lr != 0 and (di != 0):
		s = s
	s = ''.join(s)
	print(s)


N = int(input())
for k in range(N):
	b = True
	string = input()
	a = list(string)
	lst = [0] * len(string)
	for i in range(len(string)):
		if string[i].isdigit():
			lst[i] = 1
		elif string[i].isupper():
			lst[i] = 2
	if lst.count(0) and lst.count(1) and lst.count(2):
		b = False
		print(''.join(a))
	elif not lst.count(0) and (not lst.count(1)):
		a[0] = 'x'
		a[1] = '1'
	elif not lst.count(1) and (not lst.count(2)):
		a[0] = '1'
		a[1] = 'X'
	elif not lst.count(0) and (not lst.count(2)):
		a[0] = 'x'
		a[1] = 'X'
	elif not lst.count(0):
		if lst.count(1) > 1:
			a[lst.index(1)] = 'x'
		elif lst.count(2) > 1:
			a[lst.index(2)] = 'x'
	elif not lst.count(1):
		if lst.count(2) > 1:
			a[lst.index(2)] = '1'
		elif lst.count(0) > 1:
			a[lst.index(0)] = '1'
	elif not lst.count(2):
		if lst.count(0) > 1:
			a[lst.index(0)] = 'X'
		elif lst.count(1) > 1:
			a[lst.index(1)] = 'X'
	if b:
		print(''.join(a))


sett = ['1', 'l', 'L']
let = [0, 0, 0]

def func(num1, num2):
	if num1 == 0 or num2 == 0:
		if num1 == 1 or num2 == 1:
			return 2
		return 1
	return 0
n = int(input())
for i in range(n):
	s = input()
	for ch in s:
		if ch.isdecimal():
			let[0] += 1
		if ch.islower():
			let[1] += 1
		if ch.isupper():
			let[2] += 1
	n1 = n2 = -1
	for idx in range(len(let)):
		if let[idx] == 0:
			if n1 == -1:
				n1 = idx
			else:
				n2 = idx
	if n1 == -1:
		print(s)
		let[0] = let[1] = let[2] = 0
		continue
	if n2 != -1:
		s = sett[n1] + sett[n2] + s[2:]
	elif let.count(1) == 1:
		n2 = let.index(1)
		if n2 == 2:
			for idx in range(len(s) - 1):
				if not s[idx].isupper():
					if idx == 0:
						s = sett[n1] + s[1:]
					else:
						s = s[:idx] + sett[n1] + s[idx + 1:]
					break
		if n2 == 1:
			for idx in range(len(s) - 1):
				if not s[idx].islower():
					if idx == 0:
						s = sett[n1] + s[1:]
					else:
						s = s[:idx] + sett[n1] + s[idx + 1:]
					break
		if n2 == 0:
			for idx in range(len(s) - 1):
				if not s[idx].isdigit():
					if idx == 0:
						s = sett[n1] + s[1:]
					else:
						s = s[:idx] + sett[n1] + s[idx + 1:]
					break
	else:
		s = sett[n1] + s[1:]
	let[0] = let[1] = let[2] = 0
	print(s)


con = []
for i in range(int(input())):
	a = list(input())
	con.append(a)
for i in range(len(con)):
	s = con[i]
	var = ''
	if not any((c.isupper() for c in s)):
		var += 'A'
	if not any(map(str.isdigit, s)):
		var += '1'
	if not any((c.islower() for c in s)):
		var += 'a'
	if len(var) == 2:
		s[0] = var[0]
		s[1] = var[1]
		print(''.join(s))
	elif len(var) == 0:
		print(''.join(s))
	else:
		d = 0
		l = 0
		u = 0
		for j in range(len(s)):
			if s[j].isdigit() and d == 0:
				d = 1
			elif s[j].isdigit() and d == 1:
				s[j] = var[0]
				print(''.join(s))
				break
			elif s[j].islower() and l == 0:
				l = 1
			elif s[j].islower() and l == 1:
				s[j] = var[0]
				print(''.join(s))
				break
			elif s[j].isupper() and u == 0:
				u = 1
			elif s[j].isupper() and u == 1:
				s[j] = var[0]
				print(''.join(s))
				break


import string
n = int(input())

def solve(v):
	(d, dp) = (0, -1)
	(l, lp) = (0, -1)
	(u, up) = (0, -1)
	for i in range(len(v)):
		if v[i] in string.digits:
			d += 1
			if dp == -1:
				dp = i
		elif v[i] in string.ascii_lowercase:
			l += 1
			if lp == -1:
				lp = i
		else:
			u += 1
			if up == -1:
				up = i
	if d and l and u:
		return v
	if d == 0:
		if l == 0:
			v[0] = 1
			v[1] = 's'
			return v
		if u == 0:
			v[0] = 1
			v[1] = 'S'
			return v
		if l < u:
			v[up] = 1
		else:
			v[lp] = 1
		return v
	if l == 0:
		if d == 0:
			v[0] = 1
			v[1] = 's'
			return v
		if u == 0:
			v[0] = 's'
			v[1] = 'S'
		if d < u:
			v[up] = 's'
		else:
			v[dp] = 's'
		return v
	if u == 0:
		if d == 0:
			v[0] = 1
			v[1] = 'S'
			return v
		if l == 0:
			v[0] = 's'
			v[1] = 'S'
		if l < d:
			v[dp] = 'S'
		else:
			v[lp] = 'S'
		return v
for i in range(n):
	print(''.join([str(x) for x in solve(list(input()))]))


import re

def sr(st, what, luck='both'):
	if luck == 'both':
		if what == 0:
			return 'aA' + st[2:]
		elif what == 1:
			return '1A' + st[2:]
		else:
			return '1a' + st[2:]
	if enough == 0:
		return re.sub('\\d', luck, st, count=1)
	elif enough == 1:
		return re.sub('[a-z]', luck, st, count=1)
	else:
		return re.sub('[A-Z]', luck, st, count=1)
n = input()
output = ''
for i in range(int(n)):
	st = input()
	num = 0
	low = 0
	high = 0
	luck = None
	enough = None
	for x in st:
		if x.isdigit():
			num += 1
		elif x.islower():
			low += 1
		elif x.isupper():
			high += 1
	if num * high * low != 0:
		output += st + '\n'
	else:
		(luck, enough) = (0, 0)
		if num >= 2:
			enough = 0
		elif low >= 2:
			enough = 1
		elif high >= 2:
			enough = 2
		if num * high != 0 or high * low != 0 or num * low != 0:
			if num == 0:
				luck = '1'
			elif low == 0:
				luck = 'a'
			elif high == 0:
				luck = 'A'
			output += sr(st, enough, luck) + '\n'
		elif num + high == 0 or num + low == 0 or high + low == 0:
			output += sr(st, enough) + '\n'
print(output)


for _ in range(int(input())):
	s = list(input())
	(x, y, z) = (0, 0, 0)
	for i in s:
		if i.islower():
			x += 1
		elif i.isupper():
			y += 1
		elif i.isdigit():
			z += 1
	if x + y == 0 or y + z == 0 or z + x == 0:
		if s[0].islower():
			(s[0], s[1]) = ('A', '1')
		elif s[0].isupper():
			(s[0], s[1]) = ('a', '1')
		else:
			(s[0], s[1]) = ('A', 'a')
	elif x == 0 and y * z > 0:
		if y >= 2:
			tmp = 0
			for i in range(len(s)):
				if s[i].isupper():
					tmp += 1
				if tmp == 2:
					s[i] = 'a'
					break
		elif z >= 2:
			tmp = 0
			for i in range(len(s)):
				if s[i].isdigit():
					tmp += 1
				if tmp == 2:
					s[i] = 'a'
					break
	elif y == 0 and x * z > 0:
		if x >= 2:
			tmp = 0
			for i in range(len(s)):
				if s[i].islower():
					tmp += 1
				if tmp == 2:
					s[i] = 'A'
					break
		elif z >= 2:
			tmp = 0
			for i in range(len(s)):
				if s[i].isdigit():
					tmp += 1
				if tmp == 2:
					s[i] = 'A'
					break
	elif z == 0 and y * x > 0:
		if y >= 2:
			tmp = 0
			for i in range(len(s)):
				if s[i].isupper():
					tmp += 1
				if tmp == 2:
					s[i] = '1'
					break
		elif x >= 2:
			tmp = 0
			for i in range(len(s)):
				if s[i].islower():
					tmp += 1
				if tmp == 2:
					s[i] = '1'
					break
	print(''.join(s))


import math
import sys
DEBUG = False

def inp():
	return sys.stdin.readline().rstrip()

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def calc_cats(S, cats):
	for c in S:
		if 'a' <= c <= 'z':
			cats[0] = 1
		elif 'A' <= c <= 'Z':
			cats[1] = 1
		else:
			cats[2] = 1
REP = [[], ['a', 'A', '0'], ['aA', 'a0', 'A0']]

def solve(S):
	cats = [0, 0, 0]
	calc_cats(S, cats)
	sat = sum(cats)
	if sat == 3:
		return S
	ln = 3 - sat
	for i in range(len(S) + 1 - ln):
		bef = S[0:i]
		aft = S[i + ln:]
		for r in REP[ln]:
			t = bef + r + aft
			tcats = [0, 0, 0]
			calc_cats(t, tcats)
			if sum(tcats) == 3:
				return t
	assert False

def main():
	T = int(inp())
	for _ in range(T):
		print(solve(inp()))
main()


n = int(input())
for _ in range(n):
	s = input()
	c0 = any(('a' <= c <= 'z' for c in s))
	c1 = any(('A' <= c <= 'Z' for c in s))
	c2 = any(('0' <= c <= '9' for c in s))
	if c0 and c1 and c2:
		print(s)
	elif c0 + c1 + c2 == 1:
		if c0:
			print('A0' + s[2:])
		elif c1:
			print('a0' + s[2:])
		elif c2:
			print('aA' + s[2:])
	elif not c0:
		if ('A' <= s[1] <= 'Z') == ('A' <= s[2] <= 'Z'):
			print(s[0] + 'a' + s[2:])
		else:
			print('a' + s[1:])
	elif not c1:
		if ('a' <= s[1] <= 'z') == ('a' <= s[2] <= 'z'):
			print(s[0] + 'A' + s[2:])
		else:
			print('A' + s[1:])
	elif ('a' <= s[1] <= 'z') == ('a' <= s[2] <= 'z'):
		print(s[0] + '0' + s[2:])
	else:
		print('0' + s[1:])


n = int(input())
while n > 0:
	n -= 1
	s = input()
	l = u = d = -1
	a = b = 0
	for i in range(len(s)):
		if s[i].isupper():
			u = i
		elif s[i].islower():
			l = i
		else:
			d = i
	if l != -1 and u != -1 and (d != -1):
		print(s)
	elif l == -1 and u == -1:
		print('Ss' + s[2:])
	elif d == -1 and u == -1:
		print('1S' + s[2:])
	elif l == -1 and d == -1:
		print('1s' + s[2:])
	elif l == -1:
		for i in range(len(s)):
			if s[i].isupper():
				a += 1
			else:
				b += 1
			if a == 2 or b == 2:
				print(s[0:i] + 's' + s[i + 1:])
				break
	elif u == -1:
		for i in range(len(s)):
			if s[i].islower():
				a += 1
			else:
				b += 1
			if a == 2 or b == 2:
				print(s[0:i] + 'S' + s[i + 1:])
				break
	else:
		for i in range(len(s)):
			if s[i].isupper():
				a += 1
			else:
				b += 1
			if a == 2 or b == 2:
				print(s[0:i] + '1' + s[i + 1:])
				break


for _ in range(int(input())):
	s = list(input())
	(low, up, dig) = (0, 0, 0)
	for c in s:
		if c.isupper():
			up += 1
		elif c.islower():
			low += 1
		else:
			dig += 1
	if up > 0 and low > 0 and (dig > 0):
		print(''.join(s))
	else:
		if len(s) == low:
			s[0] = '1'
			s[1] = 'A'
		elif len(s) == up:
			s[0] = '1'
			s[1] = 'a'
		elif len(s) == dig:
			s[0] = 'a'
			s[1] = 'A'
		elif low == 0:
			if s[0].isupper() and up > 1:
				s[0] = 'a'
			elif s[0].isdigit() and dig > 1:
				s[0] = 'a'
			else:
				s[1] = 'a'
		elif up == 0:
			if s[0].islower() and low > 1:
				s[0] = 'A'
			elif s[0].isdigit() and dig > 1:
				s[0] = 'A'
			else:
				s[1] = 'A'
		elif s[0].isupper() and up > 1:
			s[0] = '1'
		elif s[0].islower() and low > 1:
			s[0] = '1'
		else:
			s[1] = '1'
		print(''.join(s))


n = int(input())
num = '0123456789'
small_letters = 'qwertyuiopasdfghjklzxcvbnm'
big_letters = 'QWERTYUIOPASDFGHJKLZXCVBNM'
for i in range(n):
	p = input()
	is_num = 0
	is_small = 0
	is_big = 0
	for c in p:
		if c in num:
			is_num += 1
		if c in small_letters:
			is_small += 1
		if c in big_letters:
			is_big += 1
	if not is_num and is_small and is_big:
		for i in range(len(p)):
			if is_small > 1 and p[i] in small_letters or (is_big > 1 and p[i] in big_letters):
				p = p[:i] + '1' + p[i + 1:]
				break
	if is_num and (not is_small) and is_big:
		for i in range(len(p)):
			if is_num > 1 and p[i] in num or (is_big > 1 and p[i] in big_letters):
				p = p[:i] + 'a' + p[i + 1:]
				break
	if is_num and is_small and (not is_big):
		for i in range(len(p)):
			if is_small > 1 and p[i] in small_letters or (is_num > 1 and p[i] in num):
				p = p[:i] + 'A' + p[i + 1:]
				break
	if not is_num and (not is_small):
		p = '1a' + p[2:]
	if not is_num and (not is_big):
		p = '1A' + p[2:]
	if not is_big and (not is_small):
		p = 'Aa' + p[2:]
	print(p)


q = int(input())
for i in range(q):
	s = list(input())
	q = [0, 0, 0]
	q1 = ['a', '1', 'A']
	d = {}
	for j in range(len(s)):
		p = 0
		if s[j].isdigit():
			p = 1
		elif s[j].upper() == s[j]:
			p = 2
		q[p] += 1
		d[j] = p
	w = 0
	for j in range(3):
		if q[j] >= 1:
			w += 1
	if w == 1:
		t = ''
		for j in range(3):
			if q[j] == 0:
				t += q1[j]
		print(t + ''.join(s[2:]))
	elif w == 2:
		t = ''
		for j in range(3):
			if q[j] == 0:
				t += q1[j]
		for j in range(len(s)):
			if q[d[j]] >= 2:
				s[j] = t
				break
		print(''.join(s))
	else:
		print(''.join(s))


def main():
	n = int(input())
	for i in range(n):
		s = input()
		hasNum = False
		hasCap = False
		hasLow = False
		ind1 = len(s)
		ind2 = len(s)
		ind3 = len(s)
		j = 0
		for elem in s:
			if elem in '0123456789':
				hasNum = True
				ind1 = j
			elif elem == elem.lower():
				hasLow = True
				ind2 = j
			else:
				ind3 = j
				hasCap = True
			j += 1
		if hasNum == True and hasCap == True and (hasLow == True):
			print(s)
		else:
			sub = ''
			if not hasNum:
				sub += '1'
			if not hasLow:
				sub += 'a'
			if not hasCap:
				sub += 'B'
			for j in range(len(s)):
				a = range(j, j + len(sub))
				if ind1 not in a and ind2 not in a and (ind3 not in a):
					s = s[:j] + sub + s[j + len(sub):]
					break
			print(s)
main()


n = int(input())
for i in range(n):
	S1 = input()
	S = []
	for i in S1:
		S.append(i)
	c_lower = 0
	c_upper = 0
	c_digit = 0
	for i in S:
		if i.islower():
			c_lower += 1
		if i.isupper():
			c_upper += 1
		if i.isdigit():
			c_digit += 1
	if c_digit == 0 or c_lower == 0 or c_upper == 0:
		for i in range(len(S)):
			if 48 <= ord(S[i]) <= 57 and c_digit >= 2:
				if c_upper == 0:
					S[i] = 'W'
					c_digit -= 1
					c_upper += 1
				elif c_lower == 0:
					S[i] = 'w'
					c_digit -= 1
					c_lower += 1
			elif ord(S[i]) >= 97 and c_lower >= 2:
				if c_upper == 0:
					S[i] = 'W'
					c_lower -= 1
					c_upper += 1
				elif c_digit == 0:
					S[i] = '1'
					c_lower -= 1
					c_digit += 1
			elif 65 <= ord(S[i]) < 97 and c_upper >= 2:
				if c_digit == 0:
					S[i] = '1'
					c_upper -= 1
					c_digit += 1
				elif c_lower == 0:
					S[i] = 'w'
					c_upper -= 1
					c_lower += 1
	StrS = ''.join(S)
	print(StrS)


upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lower = 'abcdefghijklmnopqrstuvwxyz'
nums = '0123456789'
passes = []
t = int(input())
for i in range(t):
	s = input()
	passes.append(s)

def what_pass(pas):
	low = 0
	upp = 0
	num = 0
	for symbol in pas:
		if symbol in upper:
			upp += 1
		if symbol in lower:
			low += 1
		if symbol in nums:
			num += 1
	return (low, upp, num)
for pas in passes:
	(low, upp, num) = what_pass(pas)
	if low > 0 and upp > 0 and (num > 0):
		print(pas)
	elif low == 0 and upp == 0:
		print(lower[0] + upper[0] + pas[2:])
	elif low == 0 and num == 0:
		print(lower[0] + nums[0] + pas[2:])
	elif upp == 0 and num == 0:
		print(upper[0] + nums[0] + pas[2:])
	elif low == 0:
		i = 0
		while True:
			if pas[i] in upper and upp > 1:
				print(pas[:i] + lower[0] + pas[i + 1:])
				break
			if pas[i] in nums and num > 1:
				print(pas[:i] + lower[0] + pas[i + 1:])
				break
			i += 1
	elif upp == 0:
		i = 0
		while True:
			if pas[i] in lower and low > 1:
				print(pas[:i] + upper[0] + pas[i + 1:])
				break
			if pas[i] in nums and num > 1:
				print(pas[:i] + upper[0] + pas[i + 1:])
				break
			i += 1
	elif num == 0:
		i = 0
		while True:
			if pas[i] in lower and low > 1:
				print(pas[:i] + nums[0] + pas[i + 1:])
				break
			if pas[i] in upper and upp > 1:
				print(pas[:i] + nums[0] + pas[i + 1:])
				break
			i += 1


cp = [chr(n) for n in range(ord('A'), ord('Z') + 1)]
sm = [chr(n) for n in range(ord('a'), ord('z') + 1)]
nm = [chr(n) for n in range(ord('0'), ord('9') + 1)]
for _ in range(int(input())):
	sk = [n for n in input()]
	c = 0
	s = 0
	n = 0
	for k in sk:
		if k in cp:
			c += 1
		elif k in sm:
			s += 1
		elif k in nm:
			n += 1
	if 0 in [c, s, n]:
		if n == 0 and s == 0:
			sk[0] = 'a'
			sk[1] = '5'
		elif n == 0 and c == 0:
			sk[0:2] = ['A', '5']
		elif c == 0 and s == 0:
			sk[0:2] = ['a', 'A']
		elif c == 0:
			if s != 1:
				for n in range(len(sk)):
					if sk[n] in sm:
						sk[n] = 'A'
						break
			else:
				for n in range(len(sk)):
					if sk[n] in nm:
						sk[n] = 'A'
						break
		elif s == 0:
			if c != 1:
				for n in range(len(sk)):
					if sk[n] in cp:
						sk[n] = 'a'
						break
			else:
				for n in range(len(sk)):
					if sk[n] in nm:
						sk[n] = 'a'
						break
		elif n == 0:
			if c != 1:
				for n in range(len(sk)):
					if sk[n] in cp:
						sk[n] = '6'
						break
			else:
				for n in range(len(sk)):
					if sk[n] in sm:
						sk[n] = '6'
						break
	for n in sk:
		print(n, end='')
	print()


n = int(input())
for i in range(n):
	s = input()
	upp = 0
	low = 0
	dig = 0
	import string
	for j in s:
		if j in string.ascii_lowercase:
			low += 1
		if j in string.ascii_uppercase:
			upp += 1
		if j in string.digits:
			dig += 1
	q = []
	if upp == 0:
		q.append('A')
	if low == 0:
		q.append('a')
	if dig == 0:
		q.append('0')
	s = list(s)
	for j in range(len(s)):
		if len(q) == 0:
			break
		if s[j] in string.ascii_lowercase:
			if low > 1:
				s[j] = q.pop()
		elif s[j] in string.ascii_uppercase:
			if upp > 1:
				s[j] = q.pop()
		elif s[j] in string.digits:
			if dig > 1:
				s[j] = q.pop()
	print(''.join(s))


cases = int(input().strip())

def find_lower(s):
	idx = 0
	for i in range(len(s)):
		if s[i].islower():
			idx = i
			break
	return idx

def find_upper(s):
	idx = 0
	for i in range(len(s)):
		if s[i].isupper():
			idx = i
			break
	return idx

def find_digit(s):
	idx = 0
	for i in range(len(s)):
		if s[i].isdigit():
			idx = i
			break
	return idx
for _ in range(cases):
	s = list(input().strip())
	conds = [0, 0, 0]
	for x in s:
		if x.isupper():
			conds[0] += 1
		if x.islower():
			conds[1] += 1
		if x.isdigit():
			conds[2] += 1
	if conds[0] == 0 and conds[1] == 0:
		s = list('Aa') + s[2:]
	elif conds[0] == 0 and conds[2] == 0:
		s = list('A1') + s[2:]
	elif conds[1] == 0 and conds[2] == 0:
		s = list('a1') + s[2:]
	elif conds[0] == 0:
		if conds[1] > 1:
			s[find_lower(s)] = 'A'
		elif conds[2] > 1:
			s[find_digit(s)] = 'A'
	elif conds[1] == 0:
		if conds[0] > 1:
			s[find_upper(s)] = 'a'
		elif conds[2] > 1:
			s[find_digit(s)] = 'a'
	elif conds[2] == 0:
		if conds[0] > 1:
			s[find_upper(s)] = '1'
		elif conds[1] > 1:
			s[find_lower(s)] = '1'
	print(''.join(s))


t = int(input())
while t > 0:
	t -= 1
	s = input()
	low = False
	up = False
	num = False
	lown = 0
	upn = 0
	numn = 0
	for letter in s:
		if letter.islower():
			low = True
			lown += 1
		elif letter.isupper():
			up = True
			upn += 1
		else:
			num = True
			numn += 1
	if low == False and up == True and (num == True):
		if upn > numn:
			if s[0].isdigit() and s[1].isupper():
				s = s[0] + 'a' + s[2:]
			elif s[0].isupper() and s[1].isdigit():
				s = 'a' + s[1:]
			else:
				s = 'a' + s[1:]
		elif s[0].isdigit() and s[1].isupper():
			s = 'a' + s[1:]
		elif s[0].isupper() and s[1].isdigit():
			s = s[0] + 'a' + s[2:]
		else:
			s = 'a' + s[1:]
	if low == True and up == False and (num == True):
		if lown > numn:
			if s[0].isdigit() and s[1].islower():
				s = s[0] + 'A' + s[2:]
			elif s[0].islower() and s[1].isdigit():
				s = 'A' + s[1:]
			else:
				s = 'A' + s[1:]
		elif s[0].isdigit() and s[1].islower():
			s = 'A' + s[1:]
		elif s[0].islower() and s[1].isdigit():
			s = s[0] + 'A' + s[2:]
		else:
			s = 'A' + s[1:]
	if low == True and up == True and (num == False):
		if lown > upn:
			if s[0].islower() and s[1].isupper():
				s = '1' + s[1:]
			elif s[0].isupper() and s[1].islower():
				s = s[0] + '1' + s[2:]
			else:
				s = '1' + s[1:]
		elif s[0].islower() and s[1].isupper():
			s = s[0] + '1' + s[2:]
		elif s[0].isupper() and s[1].islower():
			s = '1' + s[1:]
		else:
			s = '1' + s[1:]
	if low == False and up == False:
		s = 'a' + s[1:]
		s = s[0] + 'A' + s[2:]
	elif low == False and num == False:
		s = 'a' + s[1:]
		s = s[0] + '1' + s[2:]
	elif up == False and num == False:
		s = 'A' + s[1:]
		s = s[0] + '1' + s[2:]
	print(s)


import re

def adapt(pw):
	if bool(re.match('(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).+', pw)):
		return pw
	else:
		lower = re.finditer('(?=[a-z])', pw)
		lower_ind = [x.start(0) for x in lower]
		upper = re.finditer('(?=[A-Z])', pw)
		upper_ind = [x.start(0) for x in upper]
		num = re.finditer('(?=\\d)', pw)
		num_ind = [x.start(0) for x in num]
		if not len(lower_ind) and len(upper_ind) and len(num_ind):
			if len(upper_ind) > 1:
				pw = pw[:upper_ind[1]] + 'a' + pw[upper_ind[1] + 1:]
			elif len(num_ind) > 1:
				pw = pw[:num_ind[1]] + 'a' + pw[num_ind[1] + 1:]
		elif not len(upper_ind) and len(lower_ind) and len(num_ind):
			if len(lower_ind) > 1:
				pw = pw[:lower_ind[1]] + 'A' + pw[lower_ind[1] + 1:]
			elif len(num_ind) > 1:
				pw = pw[:num_ind[1]] + 'A' + pw[num_ind[1] + 1:]
		elif not len(num_ind) and len(lower_ind) and len(upper_ind):
			if len(lower_ind) > 1:
				pw = pw[:lower_ind[1]] + '1' + pw[lower_ind[1] + 1:]
			elif len(upper_ind) > 1:
				pw = pw[:upper_ind[1]] + '1' + pw[upper_ind[1] + 1:]
		elif not len(lower_ind) and (not len(upper_ind)) and len(num_ind):
			pw = 'a' + 'A' + pw[2:]
		elif not len(lower_ind) and (not len(num_ind)) and len(upper_ind):
			pw = 'a' + '1' + pw[2:]
		elif not len(upper_ind) and (not len(num_ind)) and len(lower_ind):
			pw = 'A' + '1' + pw[2:]
		return pw
num_tests = int(input())
for index in range(num_tests):
	pw = input()
	print(adapt(pw))


t = int(input())
for _ in range(t):
	s = list(input())
	cnt = [0] * 3
	kl = [[] for _ in range(3)]
	for (i, c) in enumerate(s):
		if c.islower():
			cnt[0] += 1
			kl[0].append(i)
		elif c.isupper():
			cnt[1] += 1
			kl[1].append(i)
		elif c.isdigit():
			cnt[2] += 1
			kl[2].append(i)
	if cnt.count(0) == 0:
		s = ''.join(s)
		print(s)
	elif cnt.count(0) == 2:
		s = ''.join(s)
		if cnt[0] > 0:
			print(s[:-2] + 'A1')
		elif cnt[1] > 0:
			print(s[:-2] + 'a1')
		elif cnt[2] > 0:
			print(s[:-2] + 'aA')
	else:
		if cnt[0] == 0:
			if cnt[1] > 1:
				s[kl[1].pop()] = 'a'
			else:
				s[kl[2].pop()] = 'a'
		elif cnt[1] == 0:
			if cnt[0] > 1:
				s[kl[0].pop()] = 'A'
			else:
				s[kl[2].pop()] = 'A'
		elif cnt[2] == 0:
			if cnt[1] > 1:
				s[kl[1].pop()] = '1'
			else:
				s[kl[0].pop()] = '1'
		s = ''.join(s)
		print(s)


UPPER = 0
LOWER = 1
DIGIT = 2
TYPE_COUNT = 3
RAND_CHAR = {UPPER: 'A', LOWER: 'a', DIGIT: '0'}

def get_type(ch):
	if ch.isupper():
		return UPPER
	elif ch.islower():
		return LOWER
	return DIGIT

def get_count(string):
	count = {}
	for ch in string:
		type = get_type(ch)
		if type in count:
			count[type] += 1
		else:
			count[type] = 1
	return count

def get_needed(count):
	needed = []
	for i in range(TYPE_COUNT):
		if i not in count:
			needed.append(i)
	return needed

def build_correct(password):
	count = get_count(password)
	if len(count) >= TYPE_COUNT:
		return password
	chars = list(password)
	needed = get_needed(count)
	for type in needed:
		for i in range(len(chars)):
			ch_type = get_type(chars[i])
			if ch_type in count and count[ch_type] > 1:
				chars[i] = RAND_CHAR[type]
				break
	return ''.join(chars)

def main():
	tests = int(input())
	for _ in range(tests):
		password = input()
		correct = build_correct(password)
		print(correct)
main()


T = int(input())
for i in range(T):
	s = input()
	(number_cnt, cnt_lower, cnt_upper) = (0, 0, 0)
	for j in range(len(s)):
		if s[j].isnumeric():
			number_cnt += 1
		elif s[j].islower():
			cnt_lower += 1
		elif s[j].isupper():
			cnt_upper += 1
	if number_cnt != 0 and cnt_lower != 0 and (cnt_upper != 0):
		print(s)
	else:
		if number_cnt == 0:
			for k in range(len(s)):
				if s[k].islower() and cnt_lower > 1 or (s[k].isupper() and cnt_upper > 1):
					s = s[:k] + '1' + s[k + 1:]
					break
		if cnt_lower == 0:
			for k in range(len(s)):
				if s[k].isnumeric() and number_cnt > 1 or (s[k].isupper() and cnt_upper > 1):
					s = s[:k] + 'a' + s[k + 1:]
					break
		if cnt_upper == 0:
			for k in range(len(s)):
				if s[k].isnumeric() and number_cnt > 1 or (s[k].islower() and cnt_lower > 1):
					s = s[:k] + 'A' + s[k + 1:]
					break
		print(s)


t = int(input())
u = set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])
for i in range(t):
	s = input()
	an = 0
	ani = -1
	ass = 0
	assi = -1
	asb = 0
	asbi = -1
	for i in range(len(s)):
		if s[i] in u:
			an += 1
			if an == 2:
				ani = i
		elif ord(s[i]) >= 97:
			ass += 1
			if ass == 2:
				assi = i
		else:
			asb += 1
			if asb == 2:
				asbi = i
	if an != 0 and ass != 0 and (asb != 0):
		print(s)
	else:
		n = len(s)
		s = list(s)
		if an == n:
			s[0] = 'a'
			s[1] = 'A'
		elif ass == n:
			s[0] = '1'
			s[1] = 'A'
		elif asb == n:
			s[0] = '1'
			s[1] = 'a'
		elif an == 0:
			if ani != -1:
				s[ani] = '1'
			elif assi != -1:
				s[assi] = '1'
			else:
				s[asbi] = '1'
		elif ass == 0:
			if ani != -1:
				s[ani] = 'a'
			elif assi != -1:
				s[assi] = 'a'
			else:
				s[asbi] = 'a'
		elif asb == 0:
			if ani != -1:
				s[ani] = 'A'
			elif assi != -1:
				s[assi] = 'A'
			else:
				s[asbi] = 'A'
		print(''.join(s))


t = int(input())
for i in range(t):
	s = input()
	t = ''
	for i in range(len(s)):
		c = s[i]
		if c.isdigit():
			t += '0'
		if c.islower():
			t += 'a'
		if c.isupper():
			t += 'A'
	if '0' not in t:
		l = False
		u = False
		for i in range(len(s)):
			c = s[i]
			if c.islower():
				if l:
					s = s[:i] + '0' + s[i + 1:]
					break
				l = True
			if c.isupper():
				if u:
					s = s[:i] + '0' + s[i + 1:]
					break
				u = True
	if 'a' not in t:
		d = False
		u = False
		for i in range(len(s)):
			c = s[i]
			if c.isdigit():
				if d:
					s = s[:i] + 'a' + s[i + 1:]
					break
				d = True
			if c.isupper():
				if u:
					s = s[:i] + 'a' + s[i + 1:]
					break
				u = True
	if 'A' not in t:
		d = False
		l = False
		for i in range(len(s)):
			c = s[i]
			if c.isdigit():
				if d:
					s = s[:i] + 'A' + s[i + 1:]
					break
				d = True
			if c.islower():
				if l:
					s = s[:i] + 'A' + s[i + 1:]
					break
				l = True
	print(s)


def is_big(char):
	return ord(char) >= 65 and ord(char) <= 90

def is_small(char):
	return ord(char) >= 97 and ord(char) <= 122

def is_num(char):
	return ord(char) >= 48 and ord(char) <= 57

def replace(string, i, char):
	s = list(string)
	s[i] = char
	return ''.join(s)

def alter(word, a, b, c):
	if a == 0 and b == 0:
		word = replace(word, 0, 'A')
		word = replace(word, 1, 'a')
	elif b == 0 and c == 0:
		word = replace(word, 0, 'a')
		word = replace(word, 1, '0')
	elif a == 0 and c == 0:
		word = replace(word, 0, 'A')
		word = replace(word, 1, '0')
	elif a == 0 and b == 1 and (c == 2):
		j = -1
		for i in range(len(word)):
			if is_num(word[i]):
				j = i
				break
		word = replace(word, j, 'A')
	elif a == 1 and b == 0 and (c == 2):
		j = -1
		for i in range(len(word)):
			if is_num(word[i]):
				j = i
				break
		word = replace(word, j, 'a')
	elif a == 2 and b == 0 and (c == 1):
		j = -1
		for i in range(len(word)):
			if is_big(word[i]):
				j = i
				break
		word = replace(word, j, 'a')
	elif a == 2 and b == 1 and (c == 0):
		j = -1
		for i in range(len(word)):
			if is_big(word[i]):
				j = i
				break
		word = replace(word, j, '0')
	elif a == 1 and b == 2 and (c == 0):
		j = -1
		for i in range(len(word)):
			if is_small(word[i]):
				j = i
				break
		word = replace(word, j, '0')
	elif a == 0 and b == 2 and (c == 1):
		j = -1
		for i in range(len(word)):
			if is_small(word[i]):
				j = i
				break
		word = replace(word, j, 'A')
	elif a == 0:
		j = -1
		for i in range(len(word)):
			if is_num(word[i]) or is_small(word[i]):
				j = i
				break
		word = replace(word, j, 'A')
	elif b == 0:
		j = -1
		for i in range(len(word)):
			if is_num(word[i]) or is_big(word[i]):
				j = i
				break
		word = replace(word, j, 'a')
	elif c == 0:
		j = -1
		for i in range(len(word)):
			if is_big(word[i]) or is_small(word[i]):
				j = i
				break
		word = replace(word, j, '0')
	return word

def wrap(word):
	nums = 0
	bigs = 0
	smls = 0
	for ch in word:
		if is_big(ch):
			bigs += 1
		elif is_small(ch):
			smls += 1
		elif is_num(ch):
			nums += 1
	if bigs > 0 and smls > 0 and (nums > 0):
		return word
	if nums > 1:
		nums = 2
	if bigs > 1:
		bigs = 2
	if smls > 1:
		smls = 2
	return alter(word, bigs, smls, nums)

def main():
	n = int(input())
	ress = []
	for i in range(n):
		word = input()
		res = wrap(word)
		ress.append(res)
	for res in ress:
		print(res)
main()


T = int(input())
for _ in range(T):
	s = input()
	small_indices = [i for (i, c) in enumerate(s) if c in 'abcdefghijklmnopqrstuvwxyz']
	caps_indices = [i for (i, c) in enumerate(s) if c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
	digits_indices = [i for (i, c) in enumerate(s) if c in '0123456789']
	total = bool(small_indices) + bool(caps_indices) + bool(digits_indices)
	if total >= 3:
		print(s)
	elif total == 2:
		if not small_indices:
			i = next(iter(caps_indices if len(caps_indices) > 1 else digits_indices))
			s = s[:i] + 'a' + s[i + 1:]
		elif not caps_indices:
			i = next(iter(small_indices if len(small_indices) > 1 else digits_indices))
			s = s[:i] + 'A' + s[i + 1:]
		elif not digits_indices:
			i = next(iter(caps_indices if len(caps_indices) > 1 else small_indices))
			s = s[:i] + '1' + s[i + 1:]
		print(s)
	elif total == 1:
		(i, j) = (small_indices or caps_indices or digits_indices)[:2]
		if small_indices:
			s = s[:i] + 'A' + s[i + 1:j] + '1' + s[j + 1:]
		elif caps_indices:
			s = s[:i] + 'a' + s[i + 1:j] + '1' + s[j + 1:]
		elif digits_indices:
			s = s[:i] + 'a' + s[i + 1:j] + 'A' + s[j + 1:]
		print(s)


s1 = ['', 'A0', 'a0', '0', 'aA', 'A', 'a', '']

def f(s):
	ind = [0, 0, 0]
	for i in s:
		if 'a' <= i <= 'z':
			ind[0] = 1
		if 'A' <= i <= 'Z':
			ind[1] = 1
		if '0' <= i <= '9':
			ind[2] = 1
	return ind[0] + ind[1] * 2 + ind[2] * 4
for _ in range(int(input())):
	s = input()
	ind = f(s)
	for i in range(len(s) - len(s1[ind]) + 1):
		s2 = s[:i] + s1[ind] + s[i + len(s1[ind]):]
		if f(s2) == 7:
			print(s2)
			break


import string
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
digits = string.digits
n = int(input())
for i in range(n):
	pw = input()
	size = len(pw)
	lowercaseFlag = 0
	uppercaseFlag = 0
	digitFlag = 0
	lowercaseList = []
	uppercaseList = []
	digitList = []
	for j in range(size):
		if pw[j] in lowercase and len(lowercaseList) < 3:
			lowercaseFlag = 1
			lowercaseList.append(j)
		if pw[j] in uppercase and len(uppercaseList) < 3:
			uppercaseFlag = 1
			uppercaseList.append(j)
		if str(pw[j]) in digits and len(digitList) < 3:
			digitFlag = 1
			digitList.append(j)
	if lowercaseFlag + uppercaseFlag + digitFlag == 3:
		pwRevised = pw
	elif lowercaseFlag + uppercaseFlag + digitFlag == 2:
		if lowercaseFlag + uppercaseFlag == 2:
			if len(lowercaseList) >= 2:
				b = list(pw)
				b[lowercaseList[1]] = str(0)
				pwRevised = ''.join(b)
			elif len(uppercaseList) >= 2:
				b = list(pw)
				b[uppercaseList[1]] = str(0)
				pwRevised = ''.join(b)
		if lowercaseFlag + digitFlag == 2:
			if len(lowercaseList) >= 2:
				b = list(pw)
				b[lowercaseList[1]] = 'A'
				pwRevised = ''.join(b)
			elif len(digitList) >= 2:
				b = list(pw)
				b[digitList[1]] = 'A'
				pwRevised = ''.join(b)
		if uppercaseFlag + digitFlag == 2:
			if len(uppercaseList) >= 2:
				b = list(pw)
				b[uppercaseList[1]] = 'a'
				pwRevised = ''.join(b)
			elif len(digitList) >= 2:
				b = list(pw)
				b[digitList[1]] = 'a'
				pwRevised = ''.join(b)
	else:
		if lowercaseFlag == 1:
			b = list(pw)
			b[0] = 'A'
			b[1] = str(1)
			pwRevised = ''.join(b)
		if uppercaseFlag == 1:
			b = list(pw)
			b[0] = 'a'
			b[1] = str(1)
			pwRevised = ''.join(b)
		if digitFlag == 1:
			b = list(pw)
			b[0] = 'A'
			b[1] = 'a'
			pwRevised = ''.join(b)
	print(pwRevised)


import string
lower = set(string.ascii_lowercase)
upper = set(string.ascii_uppercase)
digit = set(string.digits)
t = int(input())
a = [input() for s in range(t)]
for x in a:
	cl = 0
	cu = 0
	cd = 0
	for y in x:
		if y in lower:
			cl += 1
		elif y in upper:
			cu += 1
		elif y in digit:
			cd += 1
	if cl > 0 < cu and cd > 0:
		print(x)
	elif cl == cd == 0:
		ts = 'a1' + x[2:]
		print(ts)
	elif cl == cu == 0:
		print('Aa' + x[2:])
	elif cu == cd == 0:
		print('A1' + x[2:])
	elif cl == 0:
		if cu > cd:
			for letter in x:
				if letter in upper:
					ss = x.replace(letter, 'a', 1)
					print(ss)
					break
		else:
			for letter in x:
				if letter in digit:
					ss = x.replace(letter, 'a', 1)
					print(ss)
					break
	elif cu == 0:
		if cl > cd:
			for letter in x:
				if letter in lower:
					ss = x.replace(letter, 'A', 1)
					print(ss)
					break
		else:
			for letter in x:
				if letter in digit:
					ss = x.replace(letter, 'A', 1)
					print(ss)
					break
	elif cd == 0:
		if cu > cl:
			for letter in x:
				if letter in upper:
					ss = x.replace(letter, '1', 1)
					print(ss)
					break
		else:
			for letter in x:
				if letter in lower:
					ss = x.replace(letter, '1', 1)
					print(ss)
					break


n = int(input())
abc = 'qwertyuiopasdfghjklzxcvbnm'
ABC = 'QWERTYUIOPASDFGHJKLZXCVBNM'
nu = '0123456789'
d = []
for i in range(n):
	coa = 0
	coA = 0
	co1 = 0
	s = input()
	for j in range(len(s)):
		if s[j] in abc:
			coa += 1
			continue
		elif s[j] in ABC:
			coA += 1
			continue
		elif s[j] in nu:
			co1 += 1
	d.append(([coa, coA, co1], s))
for i in range(n):
	x = d[i][0]
	s = d[i][1]
	for j in range(len(s)):
		if x[0] == 0:
			if x[1] - 1 >= 1:
				if s[j] in ABC:
					if j + 1 < len(s):
						s = s[:j] + 'a' + s[j + 1:]
					else:
						s = s[:j] + 'a'
					x[0] += 1
					x[1] -= 1
			elif x[2] - 1 >= 1:
				if s[j] in nu:
					if j + 1 < len(s):
						s = s[:j] + 'a' + s[j + 1:]
					else:
						s = s[:j] + 'a'
					x[2] -= 1
					x[0] += 1
		elif x[1] == 0:
			if x[0] - 1 >= 1:
				if s[j] in abc:
					if j + 1 < len(s):
						s = s[:j] + 'A' + s[j + 1:]
					else:
						s = s[:j] + 'A'
					x[0] -= 1
					x[1] += 1
			elif x[2] - 1 >= 1:
				if s[j] in nu:
					if j + 1 < len(s):
						s = s[:j] + 'A' + s[j + 1:]
					else:
						s = s[:j] + 'A'
					x[2] -= 1
					x[1] += 1
		elif x[2] == 0:
			if x[1] - 1 >= 1:
				if s[j] in ABC:
					if j + 1 < len(s):
						s = s[:j] + '1' + s[j + 1:]
					else:
						s = s[:j] + '1'
					x[1] -= 1
					x[2] += 1
			elif x[0] - 1 >= 1:
				if s[j] in abc:
					if j + 1 < len(s):
						s = s[:j] + '1' + s[j + 1:]
					else:
						s = s[:j] + '1'
					x[0] -= 1
					x[2] += 1
	print(s)


for _ in range(int(input())):
	s = input()
	s = list(s)
	b = c = d = 0
	q = w = e = -1
	for i in range(len(s)):
		if s[i].isupper():
			b += 1
			if b == 2:
				q = i
		elif s[i].islower():
			c += 1
			if c == 2:
				w = i
		else:
			d += 1
			if d == 2:
				e = i
	if b == len(s):
		s[0] = 'a'
		s[1] = '1'
	elif c == len(s):
		s[0] = 'A'
		s[1] = '1'
	elif d == len(s):
		s[0] = 'a'
		s[1] = 'A'
	elif b > 0 and c > 0 and (d == 0):
		if b >= c:
			s[q] = '1'
		else:
			s[w] = '1'
	elif b > 0 and c == 0 and (d > 0):
		if b >= d:
			s[q] = 'a'
		else:
			s[e] = 'a'
	elif b == 0 and c > 0 and (d > 0):
		if c >= d:
			s[w] = 'A'
		else:
			s[e] = 'A'
	print(''.join(s))


n = int(input())
a = []
for i in range(n):
	a.append(input())
for i in range(len(a)):
	s = list(a[i])
	isbig = False
	issmall = False
	num = False
	for l in range(len(s)):
		if s[l].islower():
			s[l] = 'а'
		if 'A' <= s[l] <= 'Z':
			s[l] = 'б'
		if s[l].isdigit():
			s[l] = 'в'
	numa = -1
	numb = -1
	numc = -1
	try:
		numa = s.index('а')
	except:
		pass
	try:
		numb = s.index('б')
	except:
		pass
	try:
		numc = s.index('в')
	except:
		pass
	ss = 0
	if numa != -1:
		ss += 1
	if numb != -1:
		ss += 1
	if numc != -1:
		ss += 1
	if ss == 3:
		ready = a[i]
	elif ss == 2:
		if numa == -1:
			if numb != 0 and numc != 0:
				strr = list(a[i])
				strr[0] = 'a'
				ready = ''.join(strr)
			elif numb != 1 and numc != 1:
				strr = list(a[i])
				strr[1] = 'a'
				ready = ''.join(strr)
			else:
				strr = list(a[i])
				strr[2] = 'a'
				ready = ''.join(strr)
		if numb == -1:
			if numa != 0 and numc != 0:
				strr = list(a[i])
				strr[0] = 'A'
				ready = ''.join(strr)
			elif numa != 1 and numc != 1:
				strr = list(a[i])
				strr[1] = 'A'
				ready = ''.join(strr)
			else:
				strr = list(a[i])
				strr[2] = 'A'
				ready = ''.join(strr)
		if numc == -1:
			if numa != 0 and numb != 0:
				strr = list(a[i])
				strr[0] = '1'
				ready = ''.join(strr)
			elif numb != 1 and numa != 1:
				strr = list(a[i])
				strr[1] = '1'
				ready = ''.join(strr)
			else:
				strr = list(a[i])
				strr[2] = '1'
				ready = ''.join(strr)
	elif ss == 1:
		if numa != -1:
			if numa == 0 or numa == 1:
				strr = list(a[i])
				strr[0] = 'A'
				strr[1] = '1'
				ready = ''.join(strr)
			else:
				strr = list(a[i])
				strr[3] = 'A'
				strr[2] = '1'
				ready = ''.join(strr)
		if numb != -1:
			if numb == 0 or numb == 1:
				strr = list(a[i])
				strr[0] = 'a'
				strr[1] = '1'
				ready = ''.join(strr)
			else:
				strr = list(a[i])
				strr[3] = 'a'
				strr[2] = '1'
				ready = ''.join(strr)
		if numc != -1:
			if numc == 0 or numc == 1:
				strr = list(a[i])
				strr[0] = 'A'
				strr[1] = 'a'
				ready = ''.join(strr)
			else:
				strr = list(a[i])
				strr[3] = 'A'
				strr[2] = 'a'
				ready = ''.join(strr)
	print(ready)


t = int(input())
for _ in range(t):
	s = list(input())
	p = [0, 0, 0]
	for i in range(len(s)):
		if 65 <= ord(s[i]) <= 91:
			p[0] += 1
		elif 97 <= ord(s[i]) <= 122:
			p[1] += 1
		else:
			p[2] += 1
	if p[0] == 0:
		if p[1] == max(p):
			p[1] -= 1
			for i in range(len(s)):
				if 97 <= ord(s[i]) <= 122:
					s[i] = 'A'
					break
		elif p[2] == max(p):
			p[2] -= 1
			for i in range(len(s)):
				if 48 <= ord(s[i]) <= 57:
					s[i] = 'A'
					break
	if p[1] == 0:
		if p[0] == max(p):
			p[0] -= 1
			for i in range(len(s)):
				if 65 <= ord(s[i]) <= 91:
					s[i] = 'a'
					break
		elif p[2] == max(p):
			p[2] -= 1
			for i in range(len(s)):
				if 48 <= ord(s[i]) <= 57:
					s[i] = 'a'
					break
	if p[2] == 0:
		if p[0] == max(p):
			p[0] -= 1
			for i in range(len(s)):
				if 65 <= ord(s[i]) <= 91:
					s[i] = '1'
					break
		elif p[1] == max(p):
			p[1] -= 1
			for i in range(len(s)):
				if 97 <= ord(s[i]) <= 122:
					s[i] = '1'
					break
	print(''.join(s))