Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it.

Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times.

For example, consider the following string:  [Image] 

This string can encode the message «happynewyear». For this, candy canes and snowflakes should be used as follows:   candy cane 1: remove the letter w,  snowflake 1: repeat the letter p twice,  candy cane 2: leave the letter n,  snowflake 2: remove the letter w,  snowflake 3: leave the letter e. 

 [Image] 

Please note that the same string can encode different messages. For example, the string above can encode «hayewyar», «happpppynewwwwwyear», and other messages.

Andrey knows that messages from Irina usually have a length of $k$ letters. Help him to find out if a given string can encode a message of $k$ letters, and if so, give an example of such a message.


-----Input-----

The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters «*» and «?», meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed $200$.

The second line contains an integer number $k$ ($1 \leq k \leq 200$), the required message length.


-----Output-----

Print any message of length $k$ that the given string can encode, or «Impossible» if such a message does not exist.


-----Examples-----
Input
hw?ap*yn?eww*ye*ar
12

Output
happynewyear

Input
ab?a
2

Output
aa
Input
ab?a
3

Output
aba
Input
ababb
5

Output
ababb
Input
ab?a
1

Output
Impossible

Source: codeforces | Difficulty: EASY
Tags: Implementation

Constructive algorithms


Solutions:
import math
import sys
import bisect
t = 1
for _ in range(t):
	s = input()
	k = int(input())
	(cnt1, cnt2) = (0, 0)
	for i in range(len(s)):
		if s[i] == '*':
			cnt1 += 1
		if s[i] == '?':
			cnt2 += 1
	if len(s) - (cnt1 + cnt2) < k:
		if cnt1 == 0:
			print('Impossible')
		else:
			ex = k - (len(s) - (cnt1 + cnt2))
			s1 = ''
			ch = 0
			for i in range(len(s)):
				if ch == 0 and s[i] != '*' and (s[i] != '?'):
					if i + 1 < len(s):
						if s[i + 1] == '*':
							for j in range(ex + 1):
								s1 += s[i]
							ch = 1
						else:
							s1 += s[i]
					else:
						s1 += s[i]
				elif s[i] != '*' and s[i] != '?':
					s1 += s[i]
			print(s1)
	elif len(s) - (cnt1 + cnt2) > k:
		if len(s) - 2 * (cnt1 + cnt2) > k:
			print('Impossible')
		else:
			cnt = 0
			ex = len(s) - (cnt1 + cnt2) - k
			s1 = ''
			for i in range(len(s)):
				if s[i] != '*' and s[i] != '?':
					if i + 1 < len(s):
						if s[i + 1] == '*' or s[i + 1] == '?':
							if ex != 0:
								ex -= 1
							else:
								s1 += s[i]
						else:
							s1 += s[i]
					else:
						s1 += s[i]
			print(s1)
	else:
		s1 = ''
		for i in range(len(s)):
			if s[i] != '*' and s[i] != '?':
				s1 += s[i]
		print(s1)


import sys
data = sys.stdin.read().splitlines()
s = data[0]
n = int(data[1])
letters = snows = candys = 0
for ch in s:
	if ch == '?':
		candys += 1
	elif ch == '*':
		snows += 1
	else:
		letters += 1
mn = letters - snows - candys
mx = float('inf') if snows else letters
if n < mn or n > mx:
	print('Impossible')
elif snows == 0:
	rem = n - mn
	lst = []
	for ch in s:
		lst.append(ch)
		if ch == '?':
			lst.pop()
			if rem:
				rem -= 1
			else:
				lst.pop()
	print(''.join(lst))
else:
	lst = []
	rem = n - mn
	for ch in s:
		lst.append(ch)
		if ch == '?':
			lst.pop()
			lst.pop()
		elif ch == '*':
			lst.pop()
			c = lst.pop()
			if rem:
				lst.append(c * rem)
				rem = 0
	print(''.join(lst))


s = input()
k = int(input())
first = []
second = []
i = 0
while i < len(s):
	if s[i] == '?':
		first.append(i - 1)
		s = s[:i] + s[i + 1:]
	elif s[i] == '*':
		second.append(i - 1)
		s = s[:i] + s[i + 1:]
	i += 1
if len(s) == k:
	print(s)
	exit()
if len(second) > 0:
	if len(s) < k:
		print(s[:second[0]] + s[second[0]] * (k - len(s) + 1) + s[second[0] + 1:])
	else:
		for i in range(len(first)):
			s = s[:first[i]] + s[first[i] + 1:]
			for j in range(len(second)):
				if second[j] > first[i]:
					second[j] -= 1
			for j in range(len(first)):
				if first[j] > first[i]:
					first[j] -= 1
			if len(s) == k:
				print(s)
				exit()
		for i in range(len(second)):
			s = s[:second[i]] + s[second[i] + 1:]
			for j in range(len(second)):
				if second[j] > second[i]:
					second[j] -= 1
			if len(s) == k:
				print(s)
				exit()
		print('Impossible')
		exit()
elif len(s) < k:
	print('Impossible')
	exit()
else:
	for i in range(len(first)):
		s = s[:first[i]] + s[first[i] + 1:]
		for j in range(len(first)):
			if first[j] > first[i]:
				first[j] -= 1
		if len(s) == k:
			print(s)
			exit()
	print('Impossible')
	exit()


def main():
	s = input()
	n = int(input())
	cnt = 0
	str = []
	ans = ''
	for i in range(len(s)):
		if s[i] != '*' and s[i] != '?':
			cnt += 1
	if cnt == n:
		for i in range(len(s)):
			if s[i] != '?' and s[i] != '*':
				ans += s[i]
		print(ans)
		return
	temp = 0
	if cnt < n:
		for i in range(len(s)):
			if temp < n:
				if s[i] != '*' and s[i] != '?':
					str.append(s[i])
					temp += 1
					cnt -= 1
				elif cnt < n:
					if s[i] == '?':
						continue
					else:
						while temp + cnt < n:
							str.append(s[i - 1])
							temp += 1
	else:
		temp = cnt
		for i in range(len(s)):
			if temp > n:
				if s[i] != '*' and s[i] != '?':
					str.append(s[i])
				else:
					str.pop()
					temp -= 1
			elif s[i] != '*' and s[i] != '?':
				str.append(s[i])
	if len(str) != n:
		print('Impossible')
		return
	else:
		for i in range(len(str)):
			ans += str[i]
	print(ans)
main()


s = input()
c = 0
d = 0
n = int(input())
for i in s:
	if i == '?':
		c += 1
	elif i == '*':
		d += 1
c += d
l = 0
c1 = abs(n - (len(s) - c))
if len(s) - 2 * c > n or (len(s) - c < n and d == 0):
	print('Impossible')
elif n < len(s) - c:
	for i in range(len(s) - 1):
		if s[i + 1] in ['?', '*'] and c1 > 0:
			c1 -= 1
		elif s[i] not in ['?', '*']:
			print(s[i], end='')
			l += 1
	if s[-1] not in ['?', '*']:
		print(s[-1])
elif n >= len(s) - c:
	for i in s:
		if i == '*':
			print(p * c1, end='')
			c1 = 0
		elif i not in ['?', '*']:
			print(i, end='')
		p = i


def bounds(string):
	minimum = 0
	maximum = 0
	for (i, c) in enumerate(string):
		if c == '?':
			maximum += 0
			minimum -= 1
		elif c == '*':
			minimum -= 1
			maximum += float('inf')
		else:
			minimum += 1
			maximum += 1
	return (minimum, maximum)

def solve(string, n):
	(minimum, maximum) = bounds(string)
	if n > maximum or n < minimum:
		return None
	canes_remaining = string.count('?')
	flakes_remaining = string.count('*')
	if canes_remaining + flakes_remaining == 0:
		return string
	else:
		optionals_to_keep = n - minimum
		solution = []
		for (i, c) in enumerate(string):
			if c == '?' or c == '*':
				continue
			cane = False
			flake = False
			if i + 1 < len(string):
				if string[i + 1] == '?':
					cane = True
					canes_remaining -= 1
				elif string[i + 1] == '*':
					flake = True
					flakes_remaining -= 1
			if not cane and (not flake):
				solution.append(c)
			elif cane:
				if optionals_to_keep > 0:
					solution.append(c)
					optionals_to_keep -= 1
			elif flake:
				if optionals_to_keep > 0:
					if flakes_remaining == 0:
						to_fill = optionals_to_keep - canes_remaining
						solution.append(c * to_fill)
						optionals_to_keep -= to_fill
					else:
						solution.append(c)
						optionals_to_keep -= 1
		return ''.join(solution)
string = input()
n = int(input())
solution = solve(string, n)
if solution:
	print(solution)
else:
	print('Impossible')


strn = input()
inp = int(input())
snow = 0
candy = 0
flag = 0
strn_len = len(strn)
count = 0
out = ''
for x in strn:
	if x == '*':
		snow += 1
	if x == '?':
		candy += 1
count_miss = strn_len - (snow + candy) - inp
if inp < strn_len - 2 * (candy + snow):
	out = 'Impossible'
elif inp <= strn_len - (candy + snow):
	for x in strn:
		if x == '*':
			if flag < count_miss:
				out = out[:-1]
				flag += 1
		elif x == '?':
			if flag < count_miss:
				out = out[:-1]
				flag += 1
		else:
			out += x
else:
	count_excess = -1 * count_miss
	for x in strn:
		if x == '*':
			while flag < count_excess:
				out += out[-1]
				count_excess -= 1
		elif x == '?':
			count = 1
		else:
			out += x
if inp != len(out):
	out = 'Impossible'
print(out)


s = input()
k = int(input())
kl = s.count('?')
ks = s.count('*')
if len(s) - 2 * kl - 2 * ks > k or (ks == 0 and len(s) - kl < k):
	print('Impossible')
else:
	if ks != 0:
		ns = ''
		i = 1
		while i < len(s):
			if s[i] == '*' and ks != 0:
				ns += s[i - 1] * (k - len(s) + 2 * ks + 2 * kl)
				ks = 0
			if s[i] != '?' and s[i] != '*' and (s[i - 1] != '?') and (s[i - 1] != '*'):
				ns += s[i - 1]
			i += 1
		if s[-1] != '*' and s[-1] != '?':
			ns += s[-1]
	else:
		ns = ''
		kol = len(s) - k - kl
		i = 1
		while i < len(s):
			if s[i] == '?' and kol != 0:
				kol -= 1
			elif s[i] == '?' and kol == 0 or (s[i] != '?' and s[i - 1] != '?'):
				ns += s[i - 1]
			i += 1
		if s[-1] != '*' and s[-1] != '?':
			ns += s[-1]
	print(ns)


s = input()
k = int(input())
count1 = 0
count2 = 0
count3 = 0
flag2 = False
for i in s:
	if i == '?':
		count1 += 1
	elif i == '*':
		count2 += 1
		flag2 = True
	else:
		count3 += 1
flag = True
count = count3 - count2 - count1
l = 0
ans = ''
if count <= k and (count3 >= k or flag2):
	if flag2:
		for i in range(len(s) - 1):
			if s[i + 1] == '*' and flag:
				ans += s[i] * (k - count)
				flag = False
			elif s[i + 1] == '?' or s[i] == '?':
				l = 0
			elif s[i + 1] == '*' or s[i] == '*':
				l = 0
			else:
				ans += s[i]
		if len(ans) != k:
			ans += s[len(s) - 1]
		print(ans)
	else:
		tempcount = 0
		tmp = ['' for i in s]
		for i in range(len(s)):
			tmp[i] = s[i]
		for i in range(len(s)):
			if tempcount < k - count:
				if s[i] == '?':
					tmp[i] = ''
					tempcount += 1
			elif s[i] == '?':
				tmp[i] = ''
				tmp[i - 1] = ''
		ans = ''.join(tmp)
		print(ans)
else:
	print('Impossible')


s = input()
k = int(input())
a = 0
b = 0
bindex = -1
ss = ''
for i in range(0, len(s)):
	if s[i] is '?':
		a += 1
	elif s[i] is '*':
		b += 1
		bindex = i
l = len(s) - a - b
lmin = l - a - b
if k < lmin or (k > l and b == 0):
	print('Impossible')
elif l - k < 0:
	ss = s[0:bindex - 1] + s[bindex - 1] * (k - l + 1) + s[bindex + 1:]
elif l - k == 0:
	ss = s
elif l - k > 0:
	if l - k <= a:
		cnt = l - k
		i = len(s) - 1
		lc = []
		while i >= 0:
			if s[i] == '?' and cnt > 0:
				i -= 1
				cnt -= 1
			else:
				lc.append(s[i])
			i -= 1
		ss = ''.join(lc)[::-1]
	else:
		cnt = l - k - a
		i = len(s) - 1
		lc = []
		while i >= 0:
			if s[i] == '?':
				i -= 1
			elif s[i] == '*' and cnt > 0:
				i -= 1
				cnt -= 1
			else:
				lc.append(s[i])
			i -= 1
		ss = ''.join(lc)[::-1]
lc = []
for c in ss:
	if c not in ['?', '*']:
		lc.append(c)
print(''.join(lc))


count = 0
minus = 0
exist = False
string = input()
for i in string:
	if i.isalpha():
		count += 1
	elif i == '?':
		minus += 1
	else:
		exist = True
		minus += 1
Work = True
num = int(input())
if count - minus > num or (count < num and (not exist)):
	print('Impossible')
	Work = False
elif count > num:
	minus = count - num
	new_str = ''
	for i in string:
		if i == '?':
			if minus == 0:
				continue
			new_str = new_str[:-1]
			minus -= 1
		if i == '*':
			if minus == 0:
				continue
			new_str = new_str[:-1]
			minus -= 1
		elif i.isalpha():
			new_str += i
elif count == num:
	string = string.replace('?', '')
	new_str = string.replace('*', '')
else:
	string = string.replace('?', '')
	ind = string.index('*')
	string = string[:ind + 1] + string[ind + 1:].replace('*', '')
	new_str = string.replace('*', string[ind - 1] * (num - count))
if Work:
	print(new_str)


import sys
inf = float('inf')
mod = 1000000007

def fast_io():
	sys.stdin = stream(sys.stdin.read())
	sys.stdout = stream()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def get_array():
	return list(map(int, sys.stdin.readline().split()))

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

def input():
	return sys.stdin.readline()

def main():
	s = input().strip()
	k = int(input())
	count = 0
	ans = ''
	for i in range(len(s)):
		if i + 1 < len(s) and s[i] != '?' and (s[i] != '*'):
			if s[i + 1] != '?' and s[i + 1] != '*':
				count += 1
				ans += s[i]
	if s[-1] != '?' and s[-1] != '*':
		count += 1
		ans += s[-1]
	if count > k:
		print('Impossible')
		return
	if count == k:
		print(ans)
		return
	ans = ''
	flag = 0
	for i in range(len(s)):
		if i + 1 < len(s) and s[i] != '?' and (s[i] != '*'):
			if s[i + 1] != '?' and s[i + 1] != '*':
				ans += s[i]
			elif s[i + 1] == '*' and flag == 0:
				ans += s[i] * (k - count)
				flag = 1
	if s[-1] != '?' and s[-1] != '*':
		ans += s[-1]
	if flag == 1:
		print(ans)
		return
	ans = ''
	flag = 0
	other_count = 0
	for i in range(len(s)):
		if i + 1 < len(s) and s[i] != '?':
			if s[i + 1] != '?':
				ans += s[i]
			elif s[i + 1] == '?' and flag == 0:
				ans += s[i]
				other_count += 1
				if k - count == other_count:
					flag = 1
	if s[-1] != '?' and s[-1] != '*':
		ans += s[-1]
	if len(ans) != k:
		print('Impossible')
		return
	print(ans)
main()


s = input()
k = int(input())
ch7 = s.count('?')
ch8 = s.count('*')
ch = '*?'
if len(s) - ch7 - ch8 > k:
	if len(s) - ch7 - ch8 - ch7 - ch8 > k:
		print('Impossible')
	else:
		cou = len(s) - ch7 - ch8 - k
		while cou > 0:
			ind = s.find('?')
			if ind == -1:
				break
			s = s[:ind - 1] + s[ind + 1:]
			cou -= 1
		while cou > 0:
			ind = s.find('*')
			if ind == -1:
				break
			s = s[:ind - 1] + s[ind + 1:]
			cou -= 1
		s = s.replace('*', '')
		s = s.replace('?', '')
		print(s)
elif len(s) - ch7 - ch8 < k:
	if ch8 == 0:
		print('Impossible')
	else:
		cou = k - (len(s) - ch7 - ch8)
		ind = s.find('*')
		s = s[:ind] + s[ind - 1] * cou + s[ind + 1:]
		s = s.replace('*', '')
		s = s.replace('?', '')
		print(s)
else:
	s = s.replace('*', '')
	s = s.replace('?', '')
	print(s)


import sys
S = input()
k = int(input())
qu = S.count('?')
ast = S.count('*')
L = len(S)
if k < L - 2 * qu - 2 * ast:
	print('Impossible')
	sys.exit()
if ast == 0 and k > L - qu:
	print('Impossible')
	sys.exit()
ANS = ''
NOW = L - qu - ast
i = 0
while i < len(S):
	if S[i] == '?':
		if NOW > k:
			S = S[:i - 1] + S[i + 1:]
			NOW -= 1
		else:
			S = S[:i] + S[i + 1:]
		i = i - 1
		continue
	if S[i] == '*':
		if NOW < k:
			S = S[:i] + S[i - 1] * (k - NOW) + S[i + 1:]
			NOW = k
		elif NOW > k:
			S = S[:i - 1] + S[i + 1:]
			NOW -= 1
		else:
			S = S[:i] + S[i + 1:]
		i = i - 1
		continue
	i += 1
print(S)


s = input()
n = int(input())
stick = 0
snow = 0
temp = str()
for i in range(len(s)):
	if s[i] == '?':
		stick += 1
	elif s[i] == '*':
		snow += 1
	else:
		temp += s[i]
j = 0
output = str()
sticksta = stick
snowsta = snow
count = 0
for i in range(len(s)):
	if not (s[i] == '?' or s[i] == '*'):
		output += s[i]
		count += 1
	elif s[i] == '?':
		if snow == 0:
			if len(output) + len(temp) - count > n:
				output = output[:-1]
		elif snow != 0:
			output = output[:-1]
		stick -= 1
	elif s[i] == '*':
		if snow == 1 and len(output) < n:
			for j in range(n - len(temp) + count - len(output)):
				output += s[i - 1]
		elif len(output) + len(temp) - count > n:
			output = output[:-1]
		snow -= 1
if (snow == 0 and stick == 0) and len(output) != n:
	print('Impossible')
	exit()
print(output)


s = input()
k = int(input())
d = {'?': 0, '*': 0}
for x in s:
	if x == '?':
		d['?'] += 1
	if x == '*':
		d['*'] += 1
if k < len(s) - 2 * (d['?'] + d['*']):
	print('Impossible')
elif k <= len(s) - (d['?'] + d['*']):
	dec = len(s) - (d['?'] + d['*']) - k
	for i in range(len(s)):
		if dec > 0 and i < len(s) - 1 and (s[i + 1] in '?*'):
			dec -= 1
		elif s[i] not in '?*':
			print(s[i], end='')
elif d['*'] != 0:
	inc = k - (len(s) - (d['?'] + d['*']))
	for i in range(len(s)):
		while inc > 0 and i < len(s) - 1 and (s[i + 1] == '*'):
			inc -= 1
			print(s[i], end='')
		if s[i] not in '?*':
			print(s[i], end='')
else:
	print('Impossible')


s = input()
k = int(input())
m = s.count('?') + s.count('*')
if k < len(s) - 2 * m:
	print('Impossible')
else:
	d = k - (len(s) - m)
	if d >= 0:
		new = s.replace('?', '')
		index = s.find('*')
		if index != -1:
			new = new.replace('*', s[index - 1] * d, 1)
			new = new.replace('*', '')
			print(new)
		elif k > len(new):
			print('Impossible')
		else:
			new = new.replace('*', '')
			print(new)
	else:
		d = abs(d)
		l = list(s)
		count = 0
		for i in range(1, len(s)):
			if l[i] == '?' or (l[i] == '*' and l[i - 1] != '?' and (l[i - 1] != '*')):
				l[i - 1] = ''
				l[i] = ''
				count += 1
			if count == d:
				break
		new2 = ''
		for i in l:
			new2 += i
		new2 = new2.replace('?', '')
		new2 = new2.replace('*', '')
		print(new2)


s = input()
k = int(input())
r = 0
r1 = 0
for c in s:
	if c == '?':
		r += 1
	if c == '*':
		r1 += 1
t = len(s) - r - r1
if t == k:
	for c in s:
		if c != '?' and c != '*':
			print(c, end='')
	exit(0)
if t < k:
	if r1 != 0:
		f = True
		for i in range(len(s)):
			if s[i] == '*':
				if f:
					f = False
					print(s[i - 1] * (k - t), end='')
			elif s[i] != '?':
				print(s[i], end='')
		exit(0)
	else:
		print('Impossible')
elif t - (r + r1) > k:
	print('Impossible')
else:
	kol = t - k
	ans = ''
	for i in range(len(s)):
		if s[i] == '?':
			if kol > 0:
				ans = ans[:len(ans) - 1]
				kol -= 1
		elif s[i] == '*':
			if kol > 0:
				ans = ans[:len(ans) - 1]
				kol -= 1
		else:
			ans += s[i]
	print(ans)


def read(type=1):
	if type:
		file = open('input.dat', 'r')
		n = int(file.readline())
		file.close()
	else:
		s = input().strip()
		n = int(input().strip())
	return (s, n)

def solve():
	sub = 0
	add = 0
	l = 0
	for ch in s:
		if ch == '?':
			sub += 1
		elif ch == '*':
			sub += 1
			add = 1
		else:
			l += 1
	if n <= l:
		if n < l - sub:
			return 'Impossible'
		else:
			sol = ''
			dif = l - n
			for ch in s:
				if ch == '?' or ch == '*':
					dif -= 1
					if dif >= 0:
						sol = sol[0:-1]
				else:
					sol += ch
			return sol
	elif not add:
		return 'Impossible'
	else:
		sol = ''
		ok = 1
		dif = n - l
		for ch in s:
			if ch == '*':
				while dif and ok:
					sol += sol[-1]
					dif -= 1
				ok = 0
			elif ch != '?':
				sol += ch
		return sol
(s, n) = read(0)
sol = solve()
print(sol)


def GetLength(s):
	l = 0
	for i in s:
		if i != '?' and i != '*':
			l += 1
	return l

def Decrypt(s):
	snew = ''
	for i in s:
		if i != '?' and i != '*':
			snew += i
	return snew

def IncreaseLength(s, k, n):
	snew = ''
	count = 0
	for i in range(len(s)):
		if s[i] == '*' and i > 0 and (count == 0):
			snew += s[i - 1] * (k - n)
			count += 1
		snew += s[i]
	return snew

def DecreaseLength(s, k, n):
	snew = ''
	for i in range(len(s) - 1):
		if (s[i + 1] == '*' or s[i + 1] == '?') and n > k:
			n -= 1
			continue
		snew += s[i]
	snew += s[len(s) - 1]
	return snew

def Postcard(s, k):
	n = GetLength(s)
	if n < k:
		snew = IncreaseLength(s, k, n)
	elif n > k:
		count = 0
		for i in s:
			if i == '*' or i == '?':
				count += 1
		if count >= n - k:
			snew = DecreaseLength(s, k, n)
		else:
			snew = ''
	else:
		snew = s
	snew = Decrypt(snew)
	if len(snew) == k:
		return snew
	return 'Impossible'

def main():
	s = input()
	k = int(input())
	print(Postcard(s, k))
main()


u = list(input())
k = int(input())
n = len(u)
mi = 0
ok = False
cr = ['*', '?']
for i in range(n):
	if u[i] == '?':
		mi += 1
	elif u[i] == '*':
		mi += 1
		ok = True
r = n - mi
if r - mi <= k <= r:
	ans = []
	x = r - k
	u.append('-')
	for i in range(n):
		if u[i] not in cr and u[i + 1] not in cr:
			ans.append(u[i])
		elif u[i] not in cr and x == 0:
			ans.append(u[i])
		elif u[i] not in cr and x > 0:
			x -= 1
	print(''.join(ans))
elif ok and k >= r - mi:
	ans = []
	x = k - r
	for i in range(n):
		if u[i] not in cr:
			ans.append(u[i])
		elif u[i] == '*' and ok:
			ans += u[i - 1] * x
			ok = False
	print(''.join(ans))
else:
	print('Impossible')


s = list(input())
n = len(s)
l = int(input())
nz = s.count('*')
nl = s.count('?')
ns = n - nl - nz
if l < ns - nl - nz or (nz == 0 and l > ns):
	ans = 'Impossible'
elif nz == 0:
	k = ns
	for i in range(n):
		if s[i] == '?' and k > l:
			s[i] = ''
			s[i - 1] = ''
			k = k - 1
		elif s[i] == '?':
			s[i] = ''
	ans = ''.join(s)
elif ns == l:
	for i in range(n):
		if s[i] == '?' or s[i] == '*':
			s[i] = ''
	ans = ''.join(s)
else:
	c = ns - nl - nz + 1
	ind = s.index('*')
	for i in range(n):
		if (s[i] == '?' or s[i] == '*') and i != ind:
			s[i - 1] = ''
			s[i] = ''
	a = ''.join(s)
	k = l - len(a) + 1
	if k > 0:
		a1 = a[:a.find('*')]
		a2 = a[a.find('*') + 1:]
		a3 = a[a.find('*') - 1] * k
		ans = a1 + a3 + a2
	else:
		ind = s.index('*')
		s[ind] = ''
		s[ind - 1] = ''
		ans = ''.join(s)
print(ans)


s = input()
n = int(input())
co = s.count('*') + s.count('?')
if len(s) - 2 * co > n or (len(s) - co < n and s.count('*') == 0):
	print('Impossible')
elif len(s) - co < n:
	ma = n - len(s) + co
	re = ''
	i = 0
	while i < len(s):
		if s[i] == '*' and n != -13:
			re += s[i - 1] * ma
			n = -13
		elif s[i] != '*' and s[i] != '?':
			re += s[i]
		i += 1
	print(re)
else:
	n = len(s) - co - n
	re = ''
	i = 0
	while i < len(s):
		if n > 0:
			if s[i] == '*' or s[i] == '?':
				re = re[:len(re) - 1]
				n -= 1
			else:
				re += s[i]
		elif s[i] != '*' and s[i] != '?':
			re += s[i]
		i += 1
	print(re)


str1 = input()
num = int(input())
str1 = list(str1)
count = 0
temp = 0
temp2 = 0
for i in range(0, len(str1)):
	if str1[i] == '*':
		temp += 1
		str1[i] = 0
		count += 2
	if str1[i] == '?':
		temp2 += 1
		str1[i] = 1
		count += 2
if temp == 0 and temp2 == 0 and (num > len(str1)):
	print('Impossible')
elif temp == 0 and len(str1) - count // 2 < num:
	print('Impossible')
elif num < len(str1) - count:
	print('Impossible')
else:
	pro = len(str1) - count
	for i in range(0, len(str1)):
		if pro != num:
			if str1[i] == 0:
				str1[i] = ''
				pro += 1
				while pro != num:
					str1[i] += str1[i - 1]
					pro += 1
			if str1[i] == 1:
				str1[i] = 0
				pro += 1
		else:
			if str1[i] == 0:
				str1[i - 1] = 0
			if str1[i] == 1:
				str1[i] = 0
				str1[i - 1] = 0
	for i in range(0, len(str1)):
		if str1[i] != 0:
			print(str1[i], end='')


string = input().strip()
n = int(input().strip())
op_dict = dict()
impossible = True
ctr = 0
for i in range(len(string)):
	if string[i] in ['*', '?']:
		ctr += 1
		if string[i] not in op_dict:
			op_dict[string[i]] = [i]
		else:
			op_dict[string[i]].append(i)
str_len = len(string) - ctr
ans = ''
if '*' in op_dict and n >= str_len:
	impossible = False
	to_insert = op_dict['*'][0]
	str_in = ''
	while str_len < n:
		str_in += string[to_insert - 1]
		str_len += 1
	temp = string[:to_insert] + str_in + string[to_insert:]
	for i in range(len(temp)):
		if temp[i] not in ['*', '?']:
			ans += temp[i]
elif n == str_len:
	impossible = False
	for i in range(len(string)):
		if string[i] not in ['*', '?']:
			ans += string[i]
elif n >= str_len - ctr and n <= str_len:
	impossible = False
	op_list = []
	for key in op_dict:
		op_list += op_dict[key]
	op_list = set(op_list)
	for i in range(len(string)):
		if n == str_len:
			if string[i] not in ['*', '?']:
				ans += string[i]
		elif string[i] not in ['*', '?']:
			if i + 1 not in op_list:
				ans += string[i]
			else:
				str_len -= 1
if impossible:
	print('Impossible')
else:
	print(ans)


n = input()
k = int(input())
(a, c, s) = (0, 0, 0)
ans = ''
for i in range(len(n)):
	if n[i] == '?':
		c += 1
	elif n[i] == '*':
		s += 1
	else:
		a += 1
if a - c - s > k or (a < k and s == 0):
	print('Impossible')
	exit(0)
if a < k and s != 0:
	err = 0
	for i in range(len(n)):
		if n[i] == '*' and (not err) and len(ans):
			ans += ans[len(ans) - 1] * (k - a)
			err = 1
		elif 97 <= ord(n[i]) <= 122:
			ans += n[i]
		else:
			continue
else:
	err = a - k
	for i in range(len(n)):
		if n[i] in ['?', '*'] and err and len(ans):
			ans = ans[:len(ans) - 1]
			err -= 1
		elif 97 <= ord(n[i]) <= 122:
			ans += n[i]
		else:
			continue
if len(ans) != k:
	print('Impossible')
else:
	print(ans)


import re
s = input()
k = int(input())
a = s.count('*')
b = s.count('?')
k -= len(s) - (a + b) * 2
if k < 0 or (a == 0 and k > b):
	print('Impossible')
else:
	if a == 0:
		c = b - k
	else:
		c = b
	if c != 0:
		s = re.sub('.\\?', '', s, count=c)
	(s, q) = re.subn('(.)\\?', '\\1', s)
	k -= q
	if k > 0:
		s = re.sub('(.)\\*', '\\1' * k, s, count=1)
	s = re.sub('.\\*', '', s)
	print(s)


s = input()
k = int(input())
if '*' in s:
	newk = ''
	bam = len(s)
	cnt = 0
	for t in range(len(s) - 1):
		if s[t + 1] != '?' and s[t] != '?':
			newk += s[t]
		if s[t] == '*':
			cnt += 1
	if s[-1] == '*':
		cnt += 1
	if s[-1] != '?':
		newk += s[-1]
	if k + cnt * 2 < len(newk):
		print('Impossible')
	elif k + cnt * 2 == len(newk):
		zaz = ''
		for t in range(len(newk) - 1):
			if newk[t] != '*' and newk[t + 1] != '*':
				zaz += newk[t]
		if newk[-1] != '*':
			zaz += newk[-1]
		print(zaz)
	else:
		newA = ''
		z = k - (len(newk) - 2 * cnt + 1)
		fk = 1
		bi = 0
		for t in range(len(newk) - 1):
			if newk[t] != '*' and (newk[t + 1] != '*' or fk):
				newA += newk[t]
				if newk[t + 1] == '*':
					newA += newk[t] * z
					fk = 0
		if newk[-1] != '*':
			newA += newk[-1]
		print(newA)
else:
	led = s.count('?')
	if k > len(s) - led or k < len(s) - 2 * led:
		print('Impossible')
	else:
		zaaz = ''
		qqq = len(s) - led - k
		for t in range(len(s) - 1):
			if qqq and s[t + 1] == '?':
				qqq -= 1
			elif s[t] != '?':
				zaaz += s[t]
		if s[-1] != '?':
			zaaz += s[-1]
		print(zaaz)


str = list(input())

def length():
	length = 0
	for i in range(len(str)):
		if str[i] != '?' and str[i] != '*':
			length += 1
	return length
k = int(input())
lengt = length()
if lengt < k:
	if '*' in str:
		str = str[:str.index('*') - 1] + list(str[str.index('*') - 1] * (k - lengt)) + str[str.index('*') - 1:]
		for i in range(len(str)):
			if str[i] != '?' and str[i] != '*':
				print(str[i], end='')
	else:
		print('Impossible')
if lengt > k:
	if '*' in str or '?' in str:
		i = 0
		while i < len(str) - 1:
			if str[i + 1] == '?' or str[i + 1] == '*':
				del str[i]
				i -= 1
			i += 1
			if length() == k:
				break
	if length() == k:
		for i in range(len(str)):
			if str[i] != '?' and str[i] != '*':
				print(str[i], end='')
	else:
		print('Impossible')
if lengt == k:
	for i in range(len(str)):
		if str[i] != '?' and str[i] != '*':
			print(str[i], end='')


def mi():
	return map(int, input().split())
s = list(input())
k = int(input())
l = len(s)
ls = 0
cstar = 0
cstick = 0
for i in range(l):
	if s[i] != '?' and s[i] != '*':
		ls += 1
	if s[i] == '*':
		cstar += 1
	if s[i] == '?':
		cstick += 1
if k < ls:
	if ls - k > cstar + cstick:
		print('Impossible')
		exit(0)
	else:
		tbr = ls - k
		for i in range(l):
			if s[i] == '?' or s[i] == '*':
				s[i] = s[i - 1] = ''
				tbr -= 1
			if tbr == 0:
				break
		for i in range(l):
			if s[i] == '?' or s[i] == '*':
				s[i] = ''
		print(''.join(s))
elif k > ls:
	tba = k - ls
	if cstar > 0:
		for i in range(l):
			if s[i] == '*':
				s.insert(i, tba * s[i - 1])
				break
		for i in range(len(s)):
			if s[i] == '?' or s[i] == '*':
				s[i] = ''
		print(''.join(s))
	else:
		print('Impossible')
else:
	for i in range(l):
		if s[i] == '?' or s[i] == '*':
			s[i] = ''
	print(''.join(s))


s = input()
n = len(s)
k = int(input())
(k1, k2) = (0, 0)
for i in s:
	if i == '*':
		k1 += 1
	elif i == '?':
		k2 += 1
if k < n - 2 * k1 - 2 * k2:
	print('Impossible')
elif k1 == 0 and k > n - k2:
	print('Impossible')
else:
	p = n - k1 - k2
	ans = ''
	if p > k:
		c = p - k
		for i in range(n):
			if s[i] == '*' or s[i] == '?':
				continue
			if c > 0 and i + 1 < n and (s[i + 1] == '*' or s[i + 1] == '?'):
				c -= 1
			elif s[i] != '*' and s[i] != '?':
				ans += s[i]
		print(ans)
	elif p < k:
		f = 0
		for i in range(n):
			if s[i] == '?':
				continue
			elif s[i] == '*':
				if f == 0:
					f = 1
					ans += s[i - 1] * (k - p)
			else:
				ans += s[i]
		print(ans)
	else:
		for i in s:
			if i != '*' and i != '?':
				ans += i
		print(ans)


class Solution(object):

	def solve(self):
		s = input().strip()
		k = int(input().strip())
		countFix = 0
		countSpl = 0
		IMP = 'Impossible'
		flagged = False
		for ch in s:
			if ch != '*' and ch != '?':
				countFix += 1
			else:
				countSpl += 1
		if countFix == k:
			return ''.join([ch for ch in s if ch != '*' and ch != '?'])
		elif countFix > k:
			diff = countFix - k
			if countSpl < diff:
				return IMP
			else:
				rtr = ''
				for ch in s:
					if (ch == '*' or ch == '?') and diff > 0:
						rtr = rtr[:-1]
						diff -= 1
					elif ch != '*' and ch != '?':
						rtr += ch
		else:
			rtr = ''
			for ch in s:
				if ch != '?' and ch != '*':
					rtr += ch
				elif ch == '*' and (not flagged):
					rtr += rtr[-1] * (k - countFix)
					flagged = True
			if not flagged:
				return IMP
		return rtr
sol = Solution()
print(sol.solve())


a = input()
k = int(input())
ml = 0
for i in a:
	if i == '?' or i == '*':
		ml -= 1
	else:
		ml += 1
if k < ml:
	print('Impossible')
	import sys
	return
dl = k - ml
t = ''
n = len(a)
for i in range(n):
	if i + 1 < n and a[i + 1] == '?':
		if dl <= 0:
			continue
		t += a[i]
		dl -= 1
		continue
	if i + 1 < n and a[i + 1] == '*':
		if dl <= 0:
			continue
		while dl > 0:
			t += a[i]
			dl -= 1
		continue
	if a[i] not in '?*':
		t += a[i]
if len(t) == k:
	print(t)
else:
	print('Impossible')


ch = input()
n = int(input())
(snowflake, candy) = ([], [])
for i in range(0, len(ch)):
	if '*' == ch[i]:
		snowflake.append(i - 1)
	elif ch[i] == '?':
		candy.append(i - 1)

def add(ch, pos, how_much):
	return ch[:pos + 1] + ch[pos] * how_much + ch[pos + 1:]

def truncate(ch, index):
	new = ''
	for i in range(0, len(ch)):
		if i not in index:
			new = new + ch[i]
	return new

def clearify(ch):
	new = ''
	for i in ch:
		if i.isalpha():
			new = new + i
	return new
(s, c) = (len(snowflake), len(candy))
item = n - (len(ch) - (s + c))
if item > 0:
	if len(snowflake) == 0:
		print('Impossible')
		exit(0)
	else:
		ch = add(ch, snowflake[0], item)
elif item < 0:
	need = abs(item) - (s + c)
	snowflake.extend(candy)
	if need > 0:
		print('Impossible')
		exit(0)
	else:
		ch = truncate(ch, snowflake[:need] if need != 0 else snowflake)
ch = clearify(ch)
print(ch)


s = input()
n = int(input())
upper = False
lower = False
count = 0
cc = 0
for i in range(len(s)):
	if s[i] == '*':
		upper = True
	count += 1
	if s[i] == '*' or s[i] == '?':
		count -= 2
if count > n:
	lower = True
if lower or (len(s) - count + 2 * count < 2 * n and (not upper)):
	print('Impossible')
else:
	ans = ''
	add = n - count
	for i in range(len(s) - 1):
		if s[i] == '*' or s[i] == '?':
			continue
		if s[i + 1] != '*' and s[i + 1] != '?':
			ans += s[i]
		elif add > 0 and s[i + 1] == '?':
			ans += s[i]
			add -= 1
		elif add > 0 and s[i + 1] == '*':
			ans += s[i] * add
			add = 0
	if s[-1] != '*' and s[-1] != '?':
		ans += s[-1]
	print(ans)


s = input()
k = int(input())
basic_length = len(s)
s_char = s.replace('*', '').replace('?', '')
new_length = len(s_char)
occ = s.count('*')
if k < new_length:
	x = new_length - k
	y = basic_length - new_length
	if y < x:
		print('Impossible')
	else:
		l = list(s)
		for i in range(basic_length):
			if i < basic_length - 1:
				if x > 0 and (s[i + 1] == '?' or s[i + 1] == '*'):
					x -= 1
					continue
				elif s[i] != '?' and s[i] != '*':
					print(s[i], end='')
			elif s[i] != '?' and s[i] != '*':
				print(s[i], end='')
elif k == new_length:
	print(s_char)
elif k > new_length:
	if occ == 0:
		print('Impossible')
	else:
		lll = k - new_length
		place = s.find('*') - 1
		s = s[:place + 1] + lll * s[place] + s[place + 2:]
		print(s.replace('*', '').replace('?', ''))


from collections import Counter
inline = list(input())
k = int(input())
counter = Counter(inline)
count_hatena = counter['?']
count_ast = counter['*']
in_len = len(inline)
min_len = in_len - 2 * (count_hatena + count_ast)
if k < min_len:
	out = 'Impossible'
elif count_ast >= 1:
	out = ''
	found_ast = False
	need_ast_num = k - min_len
	for char in inline:
		if char == '?':
			out = out[:-1]
		elif char == '*':
			if not found_ast:
				found_ast = True
				out = out[:-1] + out[-1] * need_ast_num
			else:
				out = out[:-1]
		else:
			out += char
else:
	max_len = in_len - count_hatena
	if max_len < k:
		out = 'Impossible'
	else:
		need_hatena_num = k - min_len
		need_count = 0
		out = ''
		for char in inline:
			if char == '?':
				if need_count < need_hatena_num:
					need_count += 1
				else:
					out = out[:-1]
			else:
				out += char
print(out)


def info(s, k):
	snows = [i for (i, el) in enumerate(s) if el in {'*'}]
	candies = [i for (i, el) in enumerate(s) if el in {'?'}]
	toosmall = k < len(s) - 2 * len(snows) - 2 * len(candies)
	toobig = k > len(s) - len(candies) and len(snows) == 0
	return (snows, candies, not toobig and (not toosmall))

def f(s, k):
	(snows, candies, possible) = info(s, k)
	if not possible:
		return ''
	diff = k - (len(s) - len(snows) - len(candies))
	if diff == 0:
		return s.replace('*', '').replace('?', '')
	elif diff > 0:
		loc = snows[0]
		new = s[loc - 1] * diff
		total = s[:loc] + new + s[loc:]
		return total.replace('*', '').replace('?', '')
	else:
		lister = snows + candies
		s = [char for char in s]
		for i in range(abs(diff)):
			s[lister[i] - 1] = '?'
		s = ''.join(s)
		return s.replace('*', '').replace('?', '')
s = input()
k = int(input())
output = f(s, k)
if output:
	print(output)
else:
	print('Impossible')


s = input()
n = int(input())
(a, b) = ([], [])
for i in range(len(s)):
	if s[i] == '?':
		a.append(i)
	elif s[i] == '*':
		b.append(i)
c = sorted(a + b)
if len(s) - 2 * len(a) - 2 * len(b) > n:
	print('Impossible')
elif len(b) == 0 and len(s) - len(a) < n:
	print('Impossible')
else:
	r = s[:c[0] - 1] if len(c) > 0 else s
	l = len(s) - len(a) - len(b)
	done = 0
	if l < n:
		for i in range(len(c)):
			r += s[c[i - 1] + 1:c[i]]
			if s[c[i]] == '*' and done == 0:
				r += s[c[i] - 1] * (n - l + 1)
				done = 1
		r += s[c[-1] + 1:]
	elif len(c) != 0:
		for i in range(len(c)):
			r += s[c[i - 1] + 1:c[i] - 1]
			if l - done == n:
				r += s[c[i] - 1]
			else:
				done += 1
		r += s[c[-1] + 1:]
	print(r)


from collections import Counter
pattern = input()
N = int(input())
length = len(pattern)
c = Counter(pattern)
min_length = length - c['*'] * 2 - c['?'] * 2
max_length = 300
if '*' not in pattern:
	max_length = min(300, length - c['?'])
if min_length > N or max_length < N:
	print('Impossible')
else:
	diff = N - min_length
	ans = ''
	if '*' in pattern:
		flag = False
		i = length - 1
		while i >= 0:
			if pattern[i] == '?':
				i -= 2
				continue
			elif pattern[i] == '*':
				if not flag:
					ans = pattern[i - 1] * diff + ans
					i -= 2
					flag = True
				else:
					i -= 2
			else:
				ans = pattern[i] + ans
				i -= 1
	else:
		cnt = 0
		i = length - 1
		while i >= 0:
			if pattern[i] == '?':
				if cnt < diff:
					cnt += 1
					ans = pattern[i - 1] + ans
					i -= 2
				else:
					i -= 2
			else:
				ans = pattern[i] + ans
				i -= 1
	print(ans)


S = input()
n = int(input())
m = len(S.replace('*', '').replace('?', ''))
T = ''
for (i, s) in enumerate(S):
	if not (s == '*' or s == '?'):
		T += s
		continue
	if m == n:
		continue
	if m > n:
		T = T[:-1]
		m -= 1
	if m < n and s == '*':
		T += T[-1] * (n - m)
		m = n
print(T if len(T) == n else 'Impossible')


import math

def modi(a, m):
	return pow(a, m - 2, m)
s = str(input())
k = int(input())
val1 = s.count('?')
val2 = s.count('*')
n = len(s) - val1 - val2
if n > k and val1 + val2 < n - k:
	print('Impossible')
elif n < k and val2 == 0:
	print('Impossible')
else:
	ans = ''
	if n == k:
		for i in range(n + val1 + val2):
			if s[i] != '*' and s[i] != '?':
				ans += s[i]
		print(ans)
	elif n > k:
		c = n - k
		for i in range(n + val1 + val2):
			if c == 0:
				if s[i] != '*' and s[i] != '?':
					ans += s[i]
			elif s[i] == '*' or s[i] == '?':
				c -= 1
				ans = ans[:-1]
			else:
				ans += s[i]
		print(ans)
	else:
		cond = 1
		for i in range(n + val1 + val2):
			if s[i] == '*' and cond == 1:
				ans += s[i - 1] * (k - n)
				cond = 0
			elif s[i] != '?' and s[i] != '*':
				ans += s[i]
		print(ans)


from sys import *
fi = lambda : stdin.readline()
s = fi().strip('\n')
k = int(fi())
a = s.count('?')
b = s.count('*')
flag = -1
if len(s) - a - b >= k:
	req = len(s) - a - b - k
	flag = 0
else:
	req = k - (len(s) - a - b)
	flag = 1
if flag == 0 and req > a + b or (flag == 1 and b == 0):
	print('Impossible')
elif flag == 0:
	j = 0
	for i in range(len(s) - 1):
		if (s[i + 1] != '?' and s[i + 1] != '*') and j < req and (s[i] != '?') and (s[i] != '*'):
			print(s[i], end='')
		elif j >= req and s[i] != '?' and (s[i] != '*'):
			print(s[i], end='')
		elif s[i] == '?' or s[i] == '*':
			j += 1
	if s[-1] not in '?*':
		print(s[-1], end='')
	print()
elif flag == 1:
	p = s.find('*')
	for i in range(p):
		if s[i] != '?' and s[i] != '*':
			print(s[i], end='')
	print(s[p - 1] * req, end='')
	for i in range(p + 1, len(s)):
		if s[i] != '?' and s[i] != '*':
			print(s[i], end='')
	print()


n = input()
k = int(input())
ans = ''
x = n.count('*') + n.count('?')
w = len(n) - x
if len(n) - 2 * x > k:
	print('Impossible')
elif len(n) - x == k:
	while n.find('?') != -1:
		z = n.find('?')
		n = n[0:z] + n[z + 1:]
	while n.find('*') != -1:
		z = n.find('*')
		n = n[0:z] + n[z + 1:]
	print(n)
elif len(n) - 2 * x == k:
	while n.find('?') != -1:
		z = n.find('?')
		n = n[0:z - 1] + n[z + 1:]
	while n.find('*') != -1:
		z = n.find('*')
		n = n[0:z - 1] + n[z + 1:]
	print(n)
elif n.find('*') == -1:
	if n.find('?') == -1 and len(n) != k:
		print('Impossible')
	elif n.find('?') == -1 and len(n) == k:
		print(n)
	elif k > len(n) - x:
		print('Impossible')
	else:
		v = w - k
		for i in range(v):
			z = n.find('?')
			n = n[0:z - 1] + n[z + 1:]
		while n.find('?') != -1:
			z = n.find('?')
			n = n[0:z] + n[z + 1:]
		print(n)
elif n.find('?') == -1:
	if n.find('*') == -1 and len(n) != k:
		print('Impossible')
	elif n.find('*') == -1 and len(n) == k:
		print(n)
	else:
		u = n.count('*') - 1
		for i in range(u):
			z = n.find('*')
			n = n[0:z - 1] + n[z + 1:]
		u = n.find('*')
		print(n[0:u] + n[u - 1:u] * (k - len(n) + 1) + n[u + 1:])
else:
	while n.find('?') != -1:
		z = n.find('?')
		n = n[0:z - 1] + n[z + 1:]
	u = n.count('*') - 1
	for i in range(u):
		z = n.find('*')
		n = n[0:z - 1] + n[z + 1:]
	u = n.find('*')
	print(n[0:u] + n[u - 1:u] * (k - len(n) + 1) + n[u + 1:])


(s, k) = (input(), int(input()))
(a, b, c) = (0, 0, 0)
for item in s:
	if item == '?':
		a += 1
	elif item == '*':
		b += 1
	else:
		c += 1
if c - a - b > k or (b == 0 and c < k):
	print('Impossible')
else:
	(res, n) = ([], len(s))
	if c > k:
		diff = c - k
		for i in range(n):
			if s[i] == '?' or s[i] == '*':
				continue
			if i == n - 1:
				res.append(s[i])
				continue
			if s[i + 1] == '?' or s[i + 1] == '*':
				if diff > 0:
					diff -= 1
				else:
					res.append(s[i])
			else:
				res.append(s[i])
	else:
		diff = k - c
		for i in range(n):
			if s[i] == '?' or s[i] == '*':
				continue
			if i == n - 1:
				res.append(s[i])
				continue
			if s[i + 1] == '*':
				if diff > 0:
					res.append(s[i] * (diff + 1))
					diff = 0
				else:
					res.append(s[i])
			else:
				res.append(s[i])
	print(''.join(res))


s = input()
n = len(s)
le = int(input())
for i in range(len(s)):
	if ord(s[i]) < 97 or ord(s[i]) > 122:
		n -= 1
st = []
if le == n:
	for i in range(len(s)):
		if ord(s[i]) > 96 and ord(s[i]) < 123:
			st.append(s[i])
	for i in range(len(st)):
		print(st[i], end='')
	print()
elif le < n:
	c1 = 0
	for i in range(len(s)):
		if s[i] == '?' or s[i] == '*':
			c1 += 1
	if n - c1 > le:
		print('Impossible')
	else:
		c1 = n - le
		for i in range(len(s)):
			if ord(s[i]) > 96 and ord(s[i]) < 123:
				st.append(s[i])
			elif (s[i] == '?' or s[i] == '*') and c1 > 0:
				st.pop()
				c1 -= 1
		for i in range(len(st)):
			print(st[i], end='')
		print()
elif le > n:
	c2 = 0
	for i in range(len(s)):
		if s[i] == '*':
			c2 += 1
	if c2 == 0:
		print('Impossible')
	else:
		c2 = le - n
		for i in range(len(s)):
			if ord(s[i]) > 96 and ord(s[i]) < 123:
				st.append(s[i])
			elif s[i] == '*':
				while c2 > 0:
					st.append(s[i - 1])
					c2 -= 1
		for i in range(len(st)):
			print(st[i], end='')
		print()


m = input()
k = int(input())
l = 0
s = False
for i in range(len(m)):
	if m[i] == '?':
		l += 1
	elif m[i] == '*':
		l += 1
		s = True
if k < len(m) - l:
	if len(m) - k <= 2 * l:
		j = 1
		while len(m) - l > k:
			if m[j] == '?' or m[j] == '*':
				m = m[:j - 1] + m[j:]
			else:
				j += 1
	else:
		print('Impossible')
		exit(0)
elif k > len(m) - l:
	if s:
		j = m.find('*')
		while len(m) - l < k:
			m = m[:j] + m[j - 1] + m[j:]
			j += 1
	else:
		print('Impossible')
		exit(0)
m = m.replace('?', '').replace('*', '')
print(m)


s = input()
k = int(input())
v = s.count('?')
z = s.count('*')
kmin = len(s) - 2 * v - 2 * z
if k < kmin:
	print('Impossible')
elif z > 0:
	i = s.find('*')
	s = s[:i - 1] + s[i - 1] * (k - kmin) + s[i + 1:]
	if z > 1:
		for i in range(z - 1):
			j = s.find('*')
			s = s[:j - 1] + s[j + 1:]
	for i in range(v):
		j = s.find('?')
		s = s[:j - 1] + s[j + 1:]
	print(s)
elif v >= k - kmin:
	for i in range(k - kmin):
		j = s.find('?')
		s = s[:j] + s[j + 1:]
	for i in range(v - (k - kmin)):
		j = s.find('?')
		s = s[:j - 1] + s[j + 1:]
	print(s)
else:
	print('Impossible')


s = input()
n = int(input())
led = s.count('?')
snez = s.count('*')
b = len(s) - led - snez
flag = False
if b == n:
	for i in s:
		if i != '*' and i != '?':
			print(i, end='')
elif b < n:
	if snez == 0:
		print('Impossible')
	else:
		for i in range(len(s)):
			if s[i] == '*' and (not flag):
				print((n - b) * s[i - 1], end='')
				flag = True
			elif s[i] != '*' and s[i] != '?':
				print(s[i], end='')
elif b - n > led + snez:
	print('Impossible')
else:
	cnt = 0
	ans = s[0]
	for i in range(1, len(s)):
		if s[i] != '*' and s[i] != '?':
			ans += s[i]
		if (s[i] == '*' or s[i] == '?') and cnt < b - n:
			cnt += 1
			ans = ans[:-1]
	print(ans)


import math
s = input()
k = int(input())
if len(s) - 2 * (s.count('?') + s.count('*')) > k:
	print('Impossible')
	exit(0)
if len(s) - (s.count('?') + s.count('*')) == k:
	print(s.replace('?', '').replace('*', ''))
	exit(0)
if '*' in s:
	if len(s) - 2 * s.count('?') - s.count('*') < k:
		while '?' in s:
			find = s.find('?')
			s = s[:find - 1] + s[find + 1:]
		i = s.find('*')
		s = s.replace('*', '')
		s = s[:i] + s[i - 1] * (k - len(s)) + s[i:]
		print(s.replace('?', ''))
	else:
		while '?' in s and len(s) - s.count('?') - s.count('*') - 1 >= k:
			find = s.find('?')
			s = s[:find - 1] + s[find + 1:]
		while len(s.replace('*', '')) - 1 >= k and '*' in s:
			find = s.find('*')
			s = s[:find - 1] + s[find + 1:]
		print(s.replace('*', '').replace('?', ''))
else:
	while '?' in s and len(s.replace('?', '')) - 1 >= k:
		find = s.find('?')
		s = s[:find - 1] + s[find + 1:]
	if len(s.replace('?', '')) < k:
		print('Impossible')
	else:
		print(s.replace('?', ''))


n = list(input())
p = int(input())
j = 0
na = []
for it in n:
	if it != '?' and it != '*':
		j += 1
if j > p:
	jam = n.count('?')
	kam = n.count('*')
	lam = kam + jam
	sim = 0
	if lam >= j - p:
		for x in range(len(n)):
			if sim != j - p:
				if n[x] == '?' or n[x] == '*':
					na.pop()
					sim += 1
				else:
					na.append(n[x])
			else:
				break
		for x in range(x, len(n)):
			if n[x] != '?' and n[x] != '*':
				na.append(n[x])
		print(''.join(na))
	else:
		print('Impossible')
elif j == p:
	for it in n:
		if it != '?' and it != '*':
			na.append(it)
	print(''.join(na))
elif n.count('*') == 0:
	print('Impossible')
else:
	sam = p - j
	for x in range(len(n)):
		if n[x] == '*':
			for y in range(sam):
				na.append(n[x - 1])
			jam = x
			break
		elif n[x] != '?':
			na.append(n[x])
		else:
			pass
	for x in range(jam + 1, len(n)):
		if n[x] != '?' and n[x] != '*':
			na.append(n[x])
	print(''.join(na))


import sys
message = input()
n = int(input())
candy = 0
snowflake = 0
message_len = 0
for m in message:
	if m == '?':
		candy += 1
	elif m == '*':
		snowflake += 1
	else:
		message_len += 1
if message_len - n > candy + snowflake:
	print('Impossible')
	sys.exit()
if n - message_len > 0 and snowflake == 0:
	print('Impossible')
	sys.exit()
ans = []
lest = message_len - n
for m in message:
	if (m == '?' or m == '*') and lest > 0:
		ans.pop()
		lest -= 1
	elif m == '*' and lest < 0:
		for _ in range(-lest):
			ans.append(ans[-1])
		lest = 0
	elif m != '?' and m != '*':
		ans.append(m)
print(''.join(ans))


(a, b) = (input() + 'a', int(input()))
(s, q) = (a.count('*'), a.count('?'))
l = len(a) - 1 - (s + q) * 2
t = l
ans = ''
for i in range(len(a) - 1):
	if a[i + 1] == '*':
		ans += a[i] * (b - t) if s else ''
		t = b
		s = 0
	elif a[i + 1] == '?':
		if not s and t < b:
			ans += a[i]
			t += 1
	elif a[i] not in ['*', '?']:
		ans += a[i]
print(ans if len(ans) == b else 'Impossible')


s = list(input())
k = int(input())
ques = s.count('?')
star = s.count('*')
l = len(s) - ques - star
if l == k:
	for i in s:
		if i not in ['?', '*']:
			print(i, end='')
elif l > k:
	if ques + star < l - k:
		print('Impossible')
	else:
		i = 0
		while l > k:
			if s[i] in ['?', '*']:
				s[i - 1] = '.'
				l -= 1
			i += 1
		for i in s:
			if i not in ['?', '*', '.']:
				print(i, end='')
elif l < k:
	if star == 0:
		print('Impossible')
	else:
		i = 0
		while True:
			if s[i] == '*':
				break
			i += 1
		s[i - 1] = s[i - 1] * (k - l + 1)
		for i in s:
			if i not in ['?', '*', '.']:
				print(i, end='')


import re
s = input()
n = int(input())
(led, sn, L) = (s.count('?'), s.count('*'), len(s))
letters = L - led - sn
if n > letters and sn == 0 or letters - led - sn > n:
	print('Impossible')
elif n == letters:
	print(re.sub('\\*', '', re.sub('\\?', '', s)))
elif n < letters:
	(out, i, delta) = ('', 0, letters - n)
	while delta:
		if s[i + 1] == '?' or s[i + 1] == '*':
			i += 2
			delta -= 1
		else:
			out += s[i]
			i += 1
	out += s[i - 1:]
	print(re.sub('\\*', '', re.sub('\\?', '', out)))
else:
	s = re.sub('\\?', '', s)
	pos = s.find('*')
	delta = n - letters
	out = s[:pos] + s[pos - 1] * delta + s[pos:]
	print(re.sub('\\*', '', out))


def read_nums():
	return [int(x) for x in input().split()]

def parse_input(text, symbols='?*'):
	res = []
	prev_index = 0
	for (index, char) in enumerate(text):
		if char in symbols:
			res.append(('', text[prev_index:index - 1]))
			res.append((char, text[index - 1]))
			prev_index = index + 1
	last_chunk = text[prev_index:]
	if len(last_chunk) != 0:
		res.append(('', last_chunk))
	return res

def calc_length(parsed_input):
	res = 0
	for part in parsed_input:
		if part[0] == '':
			res += len(part[1])
	return res

def main():
	msg = input()
	(n,) = read_nums()
	parsed_input = parse_input(msg)
	length = calc_length(parsed_input)
	out = []
	for part in parsed_input:
		if part[0] == '':
			out.append(part[1])
		elif length < n:
			if part[0] == '?':
				out.append(part[1])
				length += 1
			else:
				out.append(part[1] * (n - length))
				length = n
	res = ''.join(out)
	if len(res) == n:
		print(res)
	else:
		print('Impossible')

def __starting_point():
	main()
__starting_point()


import re
s = input()
k = int(input())
question_count = s.count('?')
star_count = s.count('*')
s_len = len(s)
min_chars = s_len - 2 * (question_count + star_count)
if k < min_chars:
	print('Impossible')
else:
	lis = []
	i = 0
	tmp_list = []
	while i < s_len - 1:
		if s[i + 1] == '?' or s[i + 1] == '*':
			if tmp_list != []:
				lis.append(tmp_list)
			lis.append(list(s[i:i + 2]))
			tmp_list = []
			i += 2
		else:
			tmp_list.append(s[i])
			i += 1
	if s[-1] not in ['*', '?']:
		tmp_list.append(s[-1])
	if tmp_list:
		lis.append(tmp_list)
	diff = k - min_chars
	res = ''
	for elem in lis:
		if diff != 0 and '?' in elem:
			diff -= 1
			res += elem[0]
		elif diff != 0 and '*' in elem:
			res += elem[0] * diff
			diff = 0
		if '?' not in elem and '*' not in elem:
			res += ''.join(elem)
	if len(res) == k:
		print(res)
	else:
		print('Impossible')


import sys
s = sys.stdin.readline().strip()
k = int(sys.stdin.readline().strip())
l = len(s)
snow = s.count('*')
candy = s.count('?')
if l - 2 * snow - 2 * candy > k:
	print('Impossible')
elif snow == 0 and l - candy < k:
	print('Impossible')
elif snow == 0:
	keep = k - l + 2 * candy
	answer = []
	for i in range(0, l):
		if s[i] != '?':
			answer.append(s[i])
		elif keep > 0:
			keep = keep - 1
		else:
			x = answer.pop()
	print(''.join(answer))
else:
	keep = k - l + 2 * candy + snow
	answer = []
	for i in range(0, l):
		if s[i] != '?' and s[i] != '*':
			answer.append(s[i])
		elif s[i] == '?':
			x = answer.pop()
		else:
			while keep > 0:
				keep = keep - 1
				answer.append(s[i - 1])
			if keep < 0:
				keep = keep + 1
				x = answer.pop()
	print(''.join(answer))


s = list(str(input()))
k = int(input())
letters = len(s) - s.count('*') - s.count('?')
if k == letters:
	while '*' in s:
		s.remove('*')
	while '?' in s:
		s.remove('?')
	print(''.join(s))
elif k > letters:
	if '*' in s:
		while '?' in s:
			s.remove('?')
		while s.count('*') > 1:
			s.remove('*')
		specialLetter = s[s.index('*') - 1]
		s[s.index('*')] = specialLetter * (k - letters)
		print(''.join(s))
	else:
		print('Impossible')
elif s.count('*') + s.count('?') >= letters - k:
	while s.count('*') + s.count('?') > letters - k:
		if '*' in s:
			s.remove('*')
		else:
			s.remove('?')
	stringBuilder = ''
	while len(s) > 0:
		if len(s) == 1:
			stringBuilder += s[0]
			s.remove(s[0])
		elif s[1] == '*' or s[1] == '?':
			s.remove(s[0])
			s.remove(s[0])
		else:
			stringBuilder += s[0]
			s.remove(s[0])
	print(stringBuilder)
else:
	print('Impossible')


l = list(input())
k = int(input())
led = l.count('?')
sn = l.count('*')
dl = len(l) - led - sn
mask = [0] * len(l)
for i in range(len(l)):
	if l[i] == '?' and dl > k and (dl != k):
		mask[i] = 0
		mask[i - 1] = 0
		dl -= 1
	elif l[i] == '*' and dl > k and (dl != k):
		mask[i] = 0
		mask[i - 1] = 0
		dl -= 1
	elif l[i] == '*' and dl < k and (dl != k):
		mask[i] = 0
		mask[i - 1] = k - dl + 1
		dl = k
	elif l[i] != '?' and l[i] != '*':
		mask[i] = 1
if dl != k:
	print('Impossible')
	exit()
for i in range(len(l)):
	for k in range(mask[i]):
		print(l[i], end='')


def compute(st, k):
	cc = 0
	sf = 0
	for i in range(len(st)):
		if st[i] == '*':
			sf = sf + 1
		if st[i] == '?':
			cc = cc + 1
	n = len(st) - (cc + sf)
	if n == k:
		ret = ''
		for i in range(len(st)):
			if st[i] != '*' and st[i] != '?':
				ret = ret + st[i]
		return ret
	if k > n:
		diff = k - n
		st1 = ''
		once = True
		if not sf > 0:
			return 'Impossible'
		for i in range(len(st)):
			if st[i] == '*' and once:
				for j in range(diff):
					st1 = st1 + st[i - 1]
				once = False
				continue
			if st[i] != '*' and st[i] != '?':
				st1 = st1 + st[i]
		return st1
	else:
		diff = n - k
		if cc + sf < diff:
			return 'Impossible'
		ret = ''
		for i in range(len(st) - 1):
			if (st[i + 1] == '?' or st[i + 1] == '*') and diff > 0:
				diff = diff - 1
				continue
			if st[i] != '?' and st[i] != '*':
				ret = ret + st[i]
		if st[-1] != '*' and st[-1] != '?':
			ret = ret + st[-1]
		return ret

def main():
	st = input()
	k = int(input())
	ot = compute(st, k)
	print(ot)
main()


s = input()
n = int(input())
(a, b) = (s.count('*'), s.count('?'))
c = len(s) - a - b
if n < c - a - b:
	print('Impossible')
elif a == 0 and n > c:
	print('Impossible')
elif n <= c:
	removed = 0
	index = 0
	while index < len(s):
		if s[index] == '*' or s[index] == '?':
			if removed < c - n:
				s = s[:index - 1] + s[index + 1:]
				index -= 1
				removed += 1
			else:
				s = s[:index] + s[index + 1:]
		else:
			index += 1
	print(s)
else:
	contin = True
	while contin:
		contin = False
		seen = False
		for i in range(len(s)):
			if s[i] == '*':
				if not seen:
					seen = True
				else:
					s = s[:i - 1] + s[i + 1:]
					contin = True
					break
			elif s[i] == '?':
				s = s[:i - 1] + s[i + 1:]
				contin = True
				break
	lets = len(s) - 1
	for i in range(len(s)):
		if s[i] == '*':
			ind = i
			break
	s = s[:ind] + s[ind - 1] * (n - lets) + s[ind + 1:]
	print(s)


import sys

def solve(io):
	S = io.read_line()
	K = io.read_int()
	N = len(S)
	reps = [1] * N
	stars = []
	marks = []
	for i in range(0, N):
		if S[i] == '*':
			stars.append(i - 1)
			reps[i] = 0
			reps[i - 1] = 0
		elif S[i] == '?':
			marks.append(i - 1)
			reps[i] = 0
			reps[i - 1] = 0
	sofar = sum(reps)
	for idx in marks:
		if sofar >= K:
			break
		sofar += 1
		reps[idx] += 1
	rem = max(0, K - sofar)
	if len(stars) > 0:
		reps[stars[0]] += rem
		sofar += rem
	if sofar != K:
		io.println('Impossible')
		return
	sb = []
	for i in range(0, N):
		for _ in range(0, reps[i]):
			sb.append(S[i])
	io.println(''.join(sb))

class IO:
	in_stream = None
	out_stream = None
	raw = ''
	buf = []
	pos = 0

	def __init__(self, input_stream, output_stream):
		self.in_stream = input_stream
		self.out_stream = output_stream

	def read_to_buffer(self):
		self.raw = self.in_stream.readline().rstrip('\n')
		self.buf = self.raw.split()
		self.pos = 0

	def read_string(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		ans = self.buf[self.pos]
		self.pos += 1
		return ans

	def read_int(self):
		return int(self.read_string())

	def read_float(self):
		return float(self.read_string())

	def read_string_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_string())
		return arr

	def read_int_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_int())
		return arr

	def read_float_array(self, N, offset=0):
		arr = [None] * offset
		for _ in range(0, N):
			arr.append(self.read_float())
		return arr

	def read_line(self):
		while self.pos == len(self.buf):
			self.read_to_buffer()
		if self.pos > 0:
			raise ValueError('Cannot call read_line in the middle of a line.')
		self.pos = len(self.buf)
		return self.raw

	def print(self, *args):
		self.out_stream.write(' '.join([str(x) for x in args]))

	def println(self, *args):
		self.print(*args)
		self.print('\n')

	def println_array(self, arr, sep=' '):
		self.println(sep.join((str(x) for x in arr)))

	def flush_output(self):
		self.out_stream.flush()
pythonIO = IO(sys.stdin, sys.stdout)
solve(pythonIO)
pythonIO.flush_output()


encoded_message = input()
target_len = int(input())
question_mark_indices = []
star_sign_indices = []
both_sign_indices = []
message_text = ''
for character in encoded_message:
	if character == '?':
		question_mark_indices.append(len(message_text) - 1)
		both_sign_indices.append(len(message_text) - 1)
	elif character == '*':
		star_sign_indices.append(len(message_text) - 1)
		both_sign_indices.append(len(message_text) - 1)
	else:
		message_text += character
if target_len == len(message_text):
	print(message_text)
elif target_len > len(message_text):
	if len(star_sign_indices) == 0:
		print('Impossible')
	else:
		characters_required = target_len - len(message_text)
		idx = star_sign_indices[0]
		result = message_text[:idx] + message_text[idx] * characters_required + message_text[idx:]
		print(result)
elif len(message_text) - len(question_mark_indices) - len(star_sign_indices) > target_len:
	print('Impossible')
else:
	removed_characters_required = len(message_text) - target_len
	result = ''
	remove_list = both_sign_indices[:removed_characters_required]
	remove_idx = 0
	for (idx, character) in enumerate(message_text):
		if remove_idx < removed_characters_required and idx == remove_list[remove_idx]:
			remove_idx += 1
			continue
		else:
			result += character
	print(result)


def main():
	postcard = input()
	k = int(input())
	(letter_count, candy_count, snow_count) = (0, 0, 0)
	for c in postcard:
		if c == '?':
			candy_count += 1
		elif c == '*':
			snow_count += 1
		else:
			letter_count += 1
	if letter_count - candy_count - snow_count > k:
		print('Impossible')
		return
	if snow_count == 0 and letter_count < k:
		print('Impossible')
		return
	letter_diff = letter_count - k
	ret = ''
	for i in range(len(postcard)):
		if postcard[i] != '?' and postcard[i] != '*':
			ret += postcard[i]
		elif postcard[i] == '?':
			if letter_diff > 0:
				ret = ret[:-1]
				letter_diff -= 1
		elif letter_diff > 0:
			ret = ret[:-1]
			letter_diff -= 1
		elif letter_diff < 0:
			while letter_diff != 0:
				ret = ret + ret[-1]
				letter_diff += 1
	print(ret)
main()


s = input().strip()
k = int(input())
q = s.count('?')
a = s.count('*')
chars = len(s) - q - a
if k == chars:
	print(''.join((c for c in s if c not in '?*')))
elif k > chars:
	if a:
		idx = s.find('*')
		prefix = ''.join((c for c in s[:idx] if c != '?'))
		infix = s[idx - 1] * (k - chars)
		suffix = ''.join((c for c in s[idx + 1:] if c not in '?*'))
		print(prefix + infix + suffix)
	else:
		print('Impossible')
elif k < chars:
	lst = []
	to_drop = chars - k
	for (c, cn) in zip(s, s[1:] + '#'):
		if cn in '?*' and to_drop > 0:
			to_drop -= 1
		elif c not in '?*':
			lst.append(c)
	if len(lst) > k:
		print('Impossible')
	else:
		print(''.join(lst))


s = input()
l = [str(s[i]) for i in range(len(s))]
n = len(l)
k = int(input())
sf = 0
po = 0
ca = 0
lca = []
lsf = []
for i in range(n):
	if l[i] == '*':
		if i != 0:
			sf += 1
			lsf.append([i])
		else:
			po = 1
	elif l[i] == '?':
		if i != 0:
			ca += 1
			lca.append([i])
		else:
			po = 1
if n - 2 * sf - 2 * ca - po > k:
	print('Impossible')
else:
	l1 = []
	if sf == 0:
		if n - ca < k:
			print('Impossible')
		else:
			diff = n - ca - k
			c = 0
			for i in range(n - 1):
				if l[i + 1] == '?':
					if c >= diff:
						l1 += [l[i]]
					c += 1
				elif l[i] != '?':
					l1 += [l[i]]
			if l[n - 1] != '?':
				l1 += [l[n - 1]]
			print(''.join([str(i) for i in l1]))
	else:
		diff = k - (n - 2 * sf - 2 * ca - po)
		flag = 0
		for i in range(n - 1):
			if l[i] != '?' and l[i] != '*':
				if l[i + 1] != '?' and l[i + 1] != '*':
					l1 += [l[i]]
				elif l[i + 1] == '*' and flag == 0:
					l1 = l1 + [l[i] for j in range(diff)]
					flag = 1
		if l[n - 1] != '?' and l[n - 1] != '*':
			l1 += [l[n - 1]]
		print(''.join([str(i) for i in l1]))


s = input()
k = int(input())
rem = k - (len(s) - sum(map(lambda x: not x.isalpha(), s)) * 2)
if rem < 0:
	print('Impossible')
	exit(0)
res = []
for ch in s:
	if ch.isalpha():
		res.append(ch)
	elif ch == '?':
		if rem == 0:
			res.pop()
		else:
			rem -= 1
	elif ch == '*':
		if rem:
			res += res[-1] * (rem - 1)
			rem = 0
		else:
			res.pop()
if rem != 0:
	print('Impossible')
else:
	print(''.join(res))


s = str(input())
k = int(input())
count1 = 0
count1 = s.count('?')
count2 = s.count('*')
if count2 == 0:
	if len(s) - count1 < k or len(s) - count1 - count1 > k:
		print('Impossible')
	else:
		val = 2 * count1
		val2 = len(s) - val
		diff = k - val2
		ans = ''
		count3 = 0
		for i in range(len(s)):
			if i < len(s) - 1 and s[i + 1] == '?':
				if count3 < diff:
					ans += s[i]
					count3 += 1
			elif s[i] != '?':
				ans += s[i]
		print(ans)
elif len(s) - count1 - count1 - count2 - count2 > k:
	print('Impossible')
else:
	val = 2 * (count1 + count2)
	val2 = len(s) - val
	diff = k - val2
	flag = 0
	ans = ''
	for i in range(len(s)):
		if i < len(s) - 1 and (s[i + 1] == '*' or s[i + 1] == '?'):
			if flag == 0 and s[i + 1] == '*':
				ans += diff * s[i]
				flag = 1
		elif s[i] != '*' and s[i] != '?':
			ans += s[i]
	print(ans)


s = input()
k = int(input())
n = len(s)
star = s.count('*')
ques = s.count('?')
sticker = star + ques
if n - sticker < k and star == 0:
	print('Impossible')
elif n - sticker == k:
	for i in range(n):
		if s[i] != '*' and s[i] != '?':
			print(s[i], end='')
elif n - sticker < k:
	f = 1
	for i in range(n):
		if f:
			if s[i] == '*':
				print(s[i - 1] * (k - n + sticker), end='')
				f = 0
		if s[i] != '*' and s[i] != '?':
			print(s[i], end='')
elif n - sticker > k and sticker >= n - sticker - k:
	f = n - sticker - k
	for i in range(n - 1):
		if f:
			if s[i + 1] == '*' or s[i + 1] == '?':
				f -= 1
				continue
			elif s[i] != '*' and s[i] != '?':
				print(s[i], end='')
		elif s[i] != '*' and s[i] != '?':
			print(s[i], end='')
	if s[-1] != '*' and s[-1] != '?':
		print(s[-1])
else:
	print('Impossible')


prime = 998244353
t = 1
from math import sqrt
for test in range(t):
	s = input()
	cane = s.count('?')
	flake = s.count('*')
	n = len(s)
	k = int(input())
	if n - 2 * cane - 2 * flake > k or (flake == 0 and n - cane - flake < k):
		print('Impossible')
		continue
	else:
		a = []
		if n - cane - flake > k:
			req = n - cane - flake - k
			for i in s:
				if i == '?' or i == '*':
					if req > 0:
						a.pop()
						req -= 1
				else:
					a.append(i)
		else:
			req = k - (n - cane - flake)
			for i in s:
				if i == '?' or i == '*':
					if req > 0 and i == '*':
						while req > 0:
							a.append(a[-1])
							req -= 1
				else:
					a.append(i)
	print(''.join(a))


s = input()
n = int(input())
l = 0
f = 0
sf = False
for i in range(len(s)):
	if s[i] == '?':
		f += 1
	elif s[i] == '*':
		sf = True
		f += 1
	else:
		l += 1
min_l = l - f
if n < min_l or (n > l and sf == False):
	print('Impossible')
elif n <= l:
	ans = ''
	k = l - n
	for i in range(len(s)):
		if s[i] == '?' or s[i] == '*':
			if k > 0:
				ans = ans[:len(ans) - 1]
				k -= 1
		else:
			ans += s[i]
	print(ans)
else:
	ans = ''
	d = n - l
	for i in range(len(s)):
		if s[i] == '*':
			ans += ans[len(ans) - 1] * d
			d = 0
		elif s[i] != '?':
			ans += s[i]
	print(ans)


s = list(input())
k = int(input())
st = ''
n = len(s)
num = ch = sta = qu = 0
char = 0
for i in range(n - 1, -1, -1):
	if s[i] != '*' and s[i] != '?':
		num += 1
	else:
		if s[i] == '*':
			char = i - 1
			sta += 1
		else:
			qu += 1
		ch += 1
if k == num:
	for i in range(n):
		if s[i] != '?' and s[i] != '*':
			st += s[i]
	print(st)
	exit()
if k > num:
	st1 = ''
	st2 = ''
	if sta > 0:
		for i in range(0, char):
			if s[i] != '*' and s[i] != '?':
				st1 += s[i]
		for i in range(char + 1, n):
			if s[i] != '*' and s[i] != '?':
				st2 += s[i]
		l = len(st2 + st1)
		times = k - l
		st = st1 + s[char] * times + st2
		print(st)
		exit()
	else:
		print('Impossible')
		exit()
for i in range(n):
	if s[i] == '?' or s[i] == '*':
		s[i - 1] = '$'
		num -= 1
	if num == k:
		break
if k != num:
	print('Impossible')
else:
	ans = ''
	for i in range(n):
		if s[i] != '$' and s[i] != '*' and (s[i] != '?'):
			ans += s[i]
	print(ans)


a = input()
k = int(input())
ud = 0
dl = 0
nast = ''
flag = False
for i in range(len(a)):
	if a[i] != '?' and a[i] != '*':
		dl += 1
		nast = nast + a[i]
	else:
		ud += 1
		if a[i] == '*':
			flag = True
if k <= dl:
	ans = ''
	if dl - ud <= k:
		sei = 0
		for i in range(len(a)):
			if dl - sei != k:
				if a[i] == '*' or a[i] == '?':
					ans = ans[0:len(ans) - 1]
					sei += 1
			if a[i] != '*' and a[i] != '?':
				ans += a[i]
		print(ans)
	else:
		print('Impossible')
if k > dl:
	ans = ''
	if flag == True:
		sei = 0
		for i in range(len(a)):
			if a[i] == '*' and sei != 1:
				sei = 1
				while dl != k:
					ans = ans + ans[len(ans) - 1]
					dl += 1
			if a[i] != '*' and a[i] != '?':
				ans += a[i]
		print(ans)
	else:
		print('Impossible')


s = input()
n = int(input())
ls = 0
for i in s:
	if i != '*' and i != '?':
		ls += 1
if ls == n:
	for i in s:
		if i != '*' and i != '?':
			print(i, end='')
	exit()
if ls > n:
	ans = ''
	for i in range(1, len(s)):
		if s[i] != '*' and s[i] != '?':
			if s[i - 1] != '*' and s[i - 1] != '?':
				ans += s[i - 1]
		elif ls > n:
			ls -= 1
		else:
			ans += s[i - 1]
	if s[-1] != '*' and s[-1] != '?':
		ans += s[-1]
	if len(ans) == n:
		print(ans)
	else:
		print('Impossible')
	exit()
ans = ''
for i in range(1, len(s)):
	if n > ls and s[i] == '*':
		ans += s[i - 1] * (n - ls)
		ls = n
	if s[i - 1] != '*' and s[i - 1] != '?':
		ans += s[i - 1]
if s[-1] != '*' and s[-1] != '?':
	ans += s[-1]
if len(ans) == n:
	print(ans)
else:
	print('Impossible')


s = input()
k = int(input())
res_len = 0
ast = s.count('*')
quest = s.count('?')
for i in s:
	if i not in '*?':
		res_len += 1
if res_len == k:
	for i in s:
		if i not in '*?':
			print(i, end='')
	exit()
if res_len < k:
	if '*' not in s:
		print('Impossible')
		exit()
	ans_len = res_len - quest - ast
	dup = k - ans_len
	used = False
	s += '#'
	for i in range(len(s)):
		if s[i] == '#':
			exit()
		if s[i + 1] == '?':
			continue
		if s[i + 1] == '*' and (not used):
			used = True
			for j in range(dup):
				print(s[i], end='')
			continue
		if s[i + 1] in '?*':
			continue
		if s[i] in '?*':
			continue
		print(s[i], end='')
res = ''
s += '#'
for i in range(len(s)):
	if s[i] == '#':
		continue
	if s[i] in '?*':
		continue
	if res_len > k and s[i + 1] in '?*':
		res_len -= 1
		continue
	res += s[i]
if res_len == k:
	print(res)
else:
	print('Impossible')


s = input()
s = list(s)
k = int(input())
sf = 0
lc = 0
cs = 0
for i in range(0, len(s)):
	if s[i] == '?':
		cs += 1
	elif s[i] == '*':
		sf += 1
	elif ord(s[i]) >= 97 and ord(s[i]) <= 122 or (s[i] != '*' and s[i] != '?'):
		lc += 1
if lc == k:
	l = []
	for i in range(0, len(s)):
		if s[i] != '?' and s[i] != '*':
			l.append(s[i])
	z = ''.join((str(a) for a in l))
	print(z)
elif (lc < k or lc > k) and sf == 0 and (cs == 0):
	print('Impossible')
elif lc > k:
	l = []
	if lc - k > sf + cs:
		print('Impossible')
	else:
		c = lc - k
		for i in range(0, len(s)):
			if ord(s[i]) >= 97 and ord(s[i]) <= 122 or (s[i] != '*' and s[i] != '?'):
				l.append(s[i])
			elif c > 0 and (s[i] == '*' or s[i] == '?'):
				if len(l) != 0:
					l.pop()
					c -= 1
		z = ''.join((str(a) for a in l))
		print(z)
elif lc < k and sf == 0:
	print('Impossible')
else:
	l = []
	c = k - lc
	for i in range(0, len(s)):
		if ord(s[i]) >= 97 and ord(s[i]) <= 122 or (s[i] != '*' and s[i] != '?'):
			l.append(s[i])
		elif c > 0 and s[i] == '*':
			x = len(l)
			ch = l[x - 1]
			while c > 0:
				l.append(ch)
				c -= 1
	z = ''.join((str(a) for a in l))
	print(z)


s = input()
k = int(input())
(n, a, b) = (len(s), s.count('?'), s.count('*'))
n -= a + b
res = []
if n < k:
	if b > 0:
		added = False
		for c in s:
			if c == '?':
				continue
			elif c == '*':
				if not added:
					res += [res[-1] * (k - n)]
					added = True
			else:
				res.append(c)
elif n == k:
	for c in s:
		if c not in '?*':
			res.append(c)
elif n - a - b <= k:
	rem = n - k
	for c in s:
		if c in '?*':
			if rem > 0:
				res.pop()
				rem -= 1
		else:
			res.append(c)
res = ''.join(res)
if len(res) == k:
	print(res)
else:
	print('Impossible')


import sys, math
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
s = input().strip()
n = int(input())
q = s.count('?') + s.count('*')
if len(s) - 2 * q > n:
	print('Impossible')
elif s.count('*') > 0:
	k = s.index('*')
	p = []
	for i in range(k - 1):
		if s[i] == '?':
			p.pop()
		else:
			p.append(s[i])
	h = []
	for i in range(k + 1, len(s)):
		if s[i] == '?' or s[i] == '*':
			h.pop()
		else:
			h.append(s[i])
	ans = ''
	for i in p:
		ans += i
	ans += s[k - 1] * (n - len(p) - len(h))
	for i in h:
		ans += i
	print(ans)
elif n > len(s) - q:
	print('Impossible')
else:
	must = len(s) - 2 * q
	qno = n - must
	qno = q - qno
	p = []
	count = 0
	for i in range(len(s)):
		if s[i] == '?' and count < qno:
			p.pop()
			count += 1
		elif s[i] == '?' and count >= qno:
			continue
		else:
			p.append(s[i])
	ans = ''
	for i in p:
		ans += i
	print(ans)


a = input()
ques = a.count('?')
loli = a.count('*')
k = int(input())
s1 = ''
kk = len(a) - loli - ques
if k < len(a) - ques * 2 - loli * 2:
	print('Impossible')
elif k <= kk:
	dif = kk - k
	i = 0
	while dif != 0:
		if a[i + 1] == '*' or a[i + 1] == '?':
			i += 2
			dif -= 1
		else:
			s1 += a[i]
			i += 1
	while i < len(a):
		if a[i] != '*' and a[i] != '?':
			s1 += a[i]
		i += 1
	print(s1)
else:
	if loli == 0:
		print('Impossible')
	else:
		dif = k - kk
		i = 0
		while a[i] != '*':
			if a[i] != '?':
				s1 += a[i]
			i += 1
		s1 += a[i - 1] * dif
		while i < len(a):
			if a[i] != '?' and a[i] != '*':
				s1 += a[i]
			i += 1
	print(s1)


import sys
import math, bisect
sys.setrecursionlimit(10 ** 6)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict

def I():
	return int(sys.stdin.readline())

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

def Neo():
	return list(map(int, sys.stdin.readline().split()))
s = input()
k = I()
IMP = 'Impossible'
l0 = len(s) - 2 * s.count('*') - 2 * s.count('?')
if l0 > k:
	print(IMP)
	exit()
lans = l0
ans = ''
for c in s:
	if c not in '*?':
		ans = ans + c
	elif c == '*':
		ans = ans[:-1] + ans[-1] * (k - lans)
		lans = k
	elif lans >= k:
		ans = ans[:-1]
	else:
		lans += 1
if lans == k:
	print(ans)
else:
	print(IMP)


s = input()
k = int(input())
l = 0
sn = 0
for i in s:
	if i == '?':
		l += 1
	elif i == '*':
		sn += 1
n = len(s)
if n - sn - l > k:
	if sn + l < n - sn - l - k:
		print('Impossible')
	else:
		ned = n - sn - l - k
		ans = ''
		for i in s:
			if ned != 0:
				if i == '?':
					ned -= 1
					ans = ans[:-1]
				elif i == '*':
					ned -= 1
					ans = ans[:-1]
			if i != '?' and i != '*':
				ans += i
		print(ans)
elif n - sn - l == k:
	ans = ''
	for i in s:
		if i != '?' and i != '*':
			ans += i
	print(ans)
elif sn == 0:
	print('Impossible')
else:
	ned = k - (n - sn - l)
	ans = ''
	for i in s:
		if ned != 0 and i == '*':
			ans += ans[-1] * ned
			ned = 0
		if i != '?' and i != '*':
			ans += i
	print(ans)


t = input()
a = int(input())
real = 0
for j in range(len(t) - 1):
	if t[j + 1] != '*' and t[j + 1] != '?' and (t[j] != '*') and (t[j] != '?'):
		real += 1
s = len(t)
if t[-1] != '*' and t[-1] != '?':
	real += 1
if real > a:
	print('Impossible')
else:
	p = a - real
	u = ''
	for j in range(s):
		if j < s - 1 and t[j] != '*' and (t[j] != '?'):
			if t[j + 1] == '*' or t[j + 1] == '?':
				if p > 0:
					if t[j + 1] == '?':
						u += t[j]
						p -= 1
					elif t[j + 1] == '*':
						u += t[j] * p
						p = 0
			else:
				u += t[j]
		elif t[j] != '*' and t[j] != '?':
			u += t[j]
	if len(u) != a:
		print('Impossible')
	else:
		print(u)


def main():
	msg = input()
	k = int(input())
	flakes = 0
	canes = 0
	for i in range(len(msg)):
		if msg[i] == '?':
			canes += 1
		elif msg[i] == '*':
			flakes += 1
	if len(msg) - flakes - canes == k:
		for i in range(len(msg)):
			if msg[i] == '?' or msg[i] == '*':
				continue
			else:
				print(msg[i], end='')
	elif len(msg) - flakes - canes < k:
		if flakes == 0:
			print('Impossible')
		else:
			pos = 0
			for i in range(len(msg)):
				if msg[i] == '*':
					pos = i
					break
			for i in range(len(msg)):
				if msg[i] == '?' or msg[i] == '*':
					continue
				elif i == pos - 1:
					for t in range(k - (len(msg) - flakes - canes) + 1):
						print(msg[i], end='')
				else:
					print(msg[i], end='')
	elif canes + flakes < -(k - (len(msg) - flakes - canes)):
		print('Impossible')
	else:
		remove = -(k - (len(msg) - flakes - canes))
		for i in range(len(msg)):
			if msg[i] == '?' or msg[i] == '*':
				continue
			elif i == len(msg) - 1:
				print(msg[i], end='')
			elif (msg[i + 1] == '?' or msg[i + 1] == '*') and remove > 0:
				remove -= 1
				continue
			else:
				print(msg[i], end='')
main()


s = input()
n = int(input())
l = len(s)
c = 0
sn = 0
for i in s:
	if i == '?':
		c += 1
	elif i == '*':
		sn += 1
if s[0] == '?':
	c -= 1
elif s[0] == '*':
	sm -= 1
l = l - c - sn
if l < n:
	if sn == 0:
		print('Impossible')
	else:
		ans = ''
		temp = 0
		for i in range(len(s)):
			if s[i] == '*' and temp == 0:
				temp = 1
				print(s[i - 1] * (n - l), end='')
			if s[i] != '?' and s[i] != '*':
				print(s[i], end='')
elif c + sn < l - n:
	print('Impossible')
else:
	temp = l - n
	for i in range(len(s) - 1):
		if temp > 0:
			if s[i + 1] != '?' and s[i + 1] != '*' and (s[i] != '?') and (s[i] != '*'):
				print(s[i], end='')
			elif s[i + 1] != '?' and s[i + 1] != '*':
				temp -= 1
		elif s[i] != '?' and s[i] != '*':
			print(s[i], end='')
	if s[-1] != '?' and s[-1] != '*':
		print(s[-1], end='')


s = input()
k = int(input())
l = len(s)
(sf, cc) = (0, 0)
for i in s:
	if i == '?':
		cc += 1
	elif i == '*':
		sf += 1
if sf == 0 and (k > l - cc or k < l - 2 * cc):
	print('Impossible')
elif k < l - 2 * (cc + sf):
	print('Impossible')
else:
	res = ''
	p = l - cc - sf
	if k == p:
		for i in s:
			if i != '*' and i != '?':
				res += i
	elif k < p:
		t = p - k
		for i in s:
			if i == '*' or i == '?':
				if t > 0:
					res = res[:len(res) - 1]
					t -= 1
			else:
				res += i
	else:
		t = k - p
		for i in s:
			if i == '*' and t > 0:
				res += res[len(res) - 1] * t
				t = 0
			if i == '*' or i == '?':
				continue
			else:
				res += i
	print(res)


def minmax(s):
	ncandy = len([x for x in s if x == '?'])
	nflakes = len([x for x in s if x == '*'])
	l = len(s)
	M = 0
	m = l - 2 * nflakes - 2 * ncandy
	if nflakes > 0:
		M = 400
	else:
		M = l - ncandy
	return (m, M, ncandy, nflakes)
s = input()
s = s.strip()
n = int(input())
(m, M, ncandy, nflakes) = minmax(s)
answer = ''
if m > n or M < n:
	print('Impossible')
else:
	cnt = m
	i = 0
	while i < len(s):
		if i < len(s) - 1 and cnt < n:
			if s[i + 1] == '?':
				answer += s[i]
				i = i + 2
				cnt = cnt + 1
			elif s[i + 1] == '*':
				while cnt < n:
					answer += s[i]
					cnt += 1
				i += 2
			else:
				answer += s[i]
				i += 1
		elif i < len(s) - 1 and s[i + 1] in '*?':
			i += 2
		else:
			answer += s[i]
			i += 1
	print(answer)


s = input()
k = int(input())
st = lp = lt = 0
for i in s:
	if i == '*':
		st += 1
	elif i == '?':
		lp += 1
	else:
		lt += 1
if k == lt:
	ans = []
	for i in s:
		if i not in ['*', '?']:
			ans.append(i)
elif k < lt:
	de = lt - k
	if st + lp < de:
		print('Impossible')
		exit()
	else:
		ans = []
		dd = 0
		for i in s:
			if i in ['*', '?'] and dd < de:
				del ans[-1]
				dd += 1
			elif i not in ['*', '?']:
				ans.append(i)
elif k > lt:
	if st == 0:
		print('Impossible')
		exit()
	df = k - lt
	ans = []
	done = False
	for i in s:
		if i == '*' and (not done):
			sym = ans[-1]
			ans += [sym for _ in range(df)]
			done = True
		elif i not in ['*', '?']:
			ans.append(i)
print(''.join(ans))


s = input()
k = int(input())
if '*' in s:
	c = ''
	j = -1
	i = 1
	while i < len(s):
		if s[i] == '?' or (s[i] == '*' and j != -1):
			s = s[:i - 1] + s[i + 1:]
		elif s[i] == '*':
			j = i - 1
			c = s[i - 1]
			s = s[:i - 1] + s[i + 1:]
		else:
			i += 1
	if k - len(s) >= 0:
		print(s[:j] + c * (k - len(s)) + s[j:])
	else:
		print('Impossible')
else:
	c = 0
	for i in s:
		if i == '?':
			c += 1
	t = len(s) - 2 * c
	if k < t or t + c < k:
		print('Impossible')
	else:
		i = 1
		co = 0
		while i < len(s):
			if s[i] == '?':
				if co < k - t:
					s = s[:i] + s[i + 1:]
					co += 1
				else:
					s = s[:i - 1] + s[i + 1:]
			else:
				i += 1
		print(s)


s = input()
k = int(input())
candycanes = s.count('?')
snowflakes = s.count('*')
x = len(s) - candycanes - snowflakes
if k > x:
	if snowflakes == 0:
		print('Impossible')
	else:
		count = k - x
		for i in range(0, len(s)):
			if s[i] == '?':
				continue
			elif s[i] == '*':
				while count != 0:
					print(s[i - 1], end='')
					count -= 1
			else:
				print(s[i], end='')
elif k == x:
	for c in s:
		if c == '?' or c == '*':
			continue
		else:
			print(c, end='')
elif x - (snowflakes + candycanes) > k:
	print('Impossible')
else:
	count = 0
	i = 0
	n = len(s)
	while i < n:
		if s[i] == '?' or s[i] == '*':
			s = s[:i - 1] + s[i + 1:]
			count += 1
			i -= 2
			n -= 2
		if count == x - k:
			break
		i += 1
	for c in s:
		if c == '?' or c == '*':
			continue
		else:
			print(c, end='')


stra = input()
k = int(input())
counter = 0
for i in stra:
	if i != '*' and i != '?':
		counter += 1
if k < counter - (stra.count('*') + stra.count('?')):
	print('Impossible')
elif '*' not in stra and k > counter:
	print('Impossible')
elif k < counter:
	for i in range(len(stra) - 1):
		if stra[i] != '*' and stra[i] != '?':
			if stra[i + 1] != '*' and stra[i + 1] != '?':
				print(stra[i], end='')
			elif k == counter:
				print(stra[i], end='')
			else:
				counter -= 1
	if stra[-1] != '*' and stra[-1] != '?':
		print(stra[-1])
else:
	checker = False
	for i in range(len(stra) - 1):
		if stra[i + 1] == '*' and (not checker):
			for g in range(k - counter + 1):
				print(stra[i], end='')
			checker = True
		elif stra[i] != '*' and stra[i] != '?':
			print(stra[i], end='')
	if stra[-1] != '*' and stra[-1] != '?':
		print(stra[-1])


s = input()
k = int(input())
n = len(s)
min_len = 0
any_snowflake = False
max_len = 0
for i in range(n):
	if s[i] == '?':
		min_len -= 1
	elif s[i] == '*':
		min_len -= 1
		any_snowflake = True
	else:
		min_len += 1
		max_len += 1
if min_len > k:
	print('Impossible')
elif max_len < k and any_snowflake == False:
	print('Impossible')
else:
	need_more = k - min_len
	new_s = ''
	for i in range(n):
		if s[i] == '?':
			if need_more == 0:
				new_s = new_s[:-1]
			else:
				need_more -= 1
		elif s[i] == '*':
			if need_more == 0:
				new_s = new_s[:-1]
			else:
				new_s += new_s[-1] * (need_more - 1)
				need_more = 0
		else:
			new_s += s[i]
	print(new_s)


s = input()
f = int(input())
if len(s) - s.count('*') - s.count('?') >= f:
	if len(s) - (s.count('*') + s.count('?')) * 2 <= f:
		s = list(s)
		while len(s) - s.count('*') - s.count('?') > f:
			if '*' in s:
				r = s.index('*')
			else:
				r = s.index('?')
			s.pop(r - 1)
			s.pop(r - 1)
		s = filter(lambda x: x != '*' and x != '?', s)
		print(*s, sep='')
	else:
		print('Impossible')
elif '*' in s:
	o = s.index('*')
	p = s[o - 1]
	for i in range(o):
		if s[i] == '?':
			o -= 1
	s = list(filter(lambda x: x != '*' and x != '?', s))
	for i in range(f - len(s)):
		s.insert(o, p)
	print(*s, sep='')
else:
	print('Impossible')


s = str(input().strip())
n = int(input())
c = 0
cq = 0
cs = 0
for i in range(0, len(s)):
	if s[i] == '?':
		cq += 1
	elif s[i] == '*':
		cs += 1
	else:
		c += 1
if cs == 0 and c < n:
	print('Impossible')
	exit()
if c - cs - cq > n:
	print('Impossible')
	exit()
i = 0
m = len(s)
if c == n:
	print(''.join([a for a in s if a != '?' and a != '*']))
elif c < n:
	while s[i] != '*' and i < m:
		i += 1
	t = s[:i] + s[i - 1] * (n - c) + s[i + 1:]
	print(''.join([a for a in t if a != '?' and a != '*']))
else:
	t = ''
	while c != n:
		if (s[i] == '?' or s[i] == '*') and (s[i - 1] != '?' and s[i - 1] != '*'):
			t = t[:-1]
			c -= 1
		elif s[i] != '?' and s[i] != '*':
			t += s[i]
		i += 1
	t = t + s[i:]
	print(''.join([a for a in t if a != '?' and a != '*']))


import math as mt
import bisect as bi
import collections as cc
I = lambda : list(map(int, input().split()))
s = list(input())
(k,) = I()
mul = []
kep = []
n = len(s)
c = 1
for i in range(1, n):
	if s[i] == '?':
		kep.append(i)
	elif s[i] == '*':
		mul.append(i)
	else:
		c += 1
if c == k:
	new = ''
	for i in range(n):
		if s[i] != '?' and s[i] != '*':
			new += s[i]
	print(new)
elif c > k:
	d = abs(c - k)
	if len(kep) + len(mul) >= d:
		while d:
			d -= 1
			if len(kep) > 0:
				t = kep.pop(0)
				s[t - 1] = '?'
			elif mul:
				t = mul.pop(0)
				s[t - 1] = '?'
		new = ''
		for i in range(n):
			if s[i] != '?' and s[i] != '*':
				new += s[i]
		print(new)
	else:
		print('Impossible')
elif c < k:
	if mul:
		d = abs(c - k)
		t = mul.pop()
		s[t] = s[t - 1] * abs(c - k)
		new = ''
		for i in range(n):
			if s[i] != '?' and s[i] != '*':
				new += s[i]
			elif s[i] == '??':
				s[i] = s[i - 1] * d
		print(new)
	else:
		print('Impossible')


s = input()
s = list(s)
k = int(input())
c = int(0)
cstar = int(0)
cque = int(0)
ans = []
for i in range(0, len(s)):
	if s[i] != '*' and s[i] != '?':
		c = c + 1
		ans.append(s[i])
	if s[i] == '*':
		cstar += 1
	if s[i] == '?':
		cque += 1
if c == k:
	ans = ''.join(ans)
	print(ans)
elif c < k:
	diff = k - c
	if cstar > 0:
		ans = []
		for i in range(len(s) - 1, -1, -1):
			if s[i] == '*':
				d = s[i - 1]
				t = s[:i]
				td = s[i + 1:]
				rep = d * diff
				rep = list(rep)
				ans = t + rep + td
				break
		ans1 = []
		for i in range(0, len(ans)):
			if ans[i] != '*' and ans[i] != '?':
				ans1.append(ans[i])
		ans1 = ''.join(ans1)
		print(ans1)
	else:
		print('Impossible')
else:
	ans1 = []
	if c - k <= cque + cstar:
		diff = c - k
		for i in range(0, len(s) - 1):
			if diff > 0:
				if s[i] != '*' and s[i] != '?':
					if s[i + 1] == '*' or s[i + 1] == '?':
						diff -= 1
					else:
						ans1.append(s[i])
			elif s[i] != '*' and s[i] != '?':
				ans1.append(s[i])
		if s[len(s) - 1] != '*' and s[len(s) - 1] != '?':
			ans1.append(s[len(s) - 1])
		ans1 = ''.join(ans1)
		print(ans1)
	else:
		print('Impossible')


def cleanup(s):
	m = ''
	for i in range(len(s)):
		if s[i] != '?' and s[i] != '*':
			m += s[i]
	return m

def delete(s, k):
	m = ''
	for i in range(len(s)):
		if i != k:
			m += s[i]
	return m

def multiply(s, k, n):
	m = ''
	for i in range(len(s)):
		if i != k:
			m += s[i]
		else:
			for j in range(n + 1):
				m += s[i]
	x = cleanup(m)
	return x
s = input()
k = int(input())
m = 0
q = 0
st = 0
a = ''
for i in range(len(s)):
	if s[i] == '?':
		q += 1
	elif s[i] == '*':
		st += 1
	else:
		m += 1
		a += s[i]
if k < m - q - st or (k > m and st == 0):
	print('Impossible')
elif k == m:
	print(a)
elif k > m:
	for i in range(len(s)):
		if s[i] == '*':
			m = multiply(s, i - 1, k - m)
			break
	print(m)
else:
	diff = m - k
	for i in range(len(s)):
		if diff:
			if s[i] == '?' or s[i] == '*':
				s = delete(s, i - 1)
				diff -= 1
		else:
			break
	print(cleanup(s))


arr = [x for x in input().strip()]
k = int(input())
q = arr.count('?')
s = arr.count('*')
n = len(arr) - q - s
if n - q - s > k or (k > n and s == 0):
	print('Impossible')
	exit()
if k > n:
	g = k - n
	i = arr.index('*')
	t = arr[i - 1]
	res = arr[:i] + [t] * g + arr[i:]
	print(''.join([x for x in res if x != '*' and x != '?']))
else:
	g = n - k
	i = 0
	res = []
	for e in arr:
		if e != '*' and e != '?':
			res.append(e)
		elif g:
			res.pop()
			g -= 1
	print(''.join(res))


s = input()
n = int(input())
g = s.count('?')
f = s.count('*')
l = len(s) - g - f
minL = len(s) - 2 * g - 2 * f
maxL = len(s) - g
if minL > n or (maxL < n and f == 0):
	print('Impossible')
elif n > l:
	n = n - l
	s = list(s)
	i = s.index('*')
	a = s[i - 1] * n
	s[i:i + 1] = a
	for i in range(g):
		s.remove('?')
	f -= 1
	for i in range(f):
		s.remove('*')
	print(''.join(s))
else:
	n = l - n
	s = list(s)
	for i in range(n):
		try:
			del s[s.index('*') - 1]
			del s[s.index('*')]
			n -= 1
			f -= 1
		except:
			break
	for i in range(n):
		try:
			del s[s.index('?') - 1]
			del s[s.index('?')]
			g -= 1
		except:
			break
	for i in range(g):
		s.remove('?')
	for i in range(f):
		s.remove('*')
	print(''.join(s))


msg = input()
k = int(input())
letters_count = 0
for l in msg:
	if l not in ('?', '*'):
		letters_count += 1
diff = letters_count - k
res = [None] * k
res_i = 0
try:
	for i in range(len(msg)):
		if msg[i] in ('?', '*'):
			continue
		if i < len(msg) - 1 and msg[i + 1] in ('?', '*') and diff:
			if diff < 0:
				if msg[i + 1] == '?':
					res[res_i] = msg[i]
					res_i += 1
				else:
					for _ in range(-diff + 1):
						res[res_i] = msg[i]
						res_i += 1
					diff = 0
			else:
				diff -= 1
		else:
			res[res_i] = msg[i]
			res_i += 1
except IndexError:
	print('Impossible')
	exit()
if res_i == k:
	print(''.join(res))
else:
	print('Impossible')


regex = input()
k = int(input())
star = 0
question = 0
for letter in regex:
	if letter == '*':
		star += 1
	elif letter == '?':
		question += 1
n = len(regex)
if star:
	if k < n - (question + star) * 2:
		print('Impossible')
	else:
		s = k - n + (question + star) * 2
		first = False
		result = ''
		for (a, b) in zip(regex[:-1], regex[1:]):
			if a not in ('?', '*'):
				if b == '*' and (not first):
					result += s * a
					first = True
				elif b not in ('?', '*'):
					result += a
		if regex[-1] not in ('?', '*'):
			result += regex[-1]
		print(result)
elif k < n - question * 2 or k > n - question:
	print('Impossible')
else:
	keep = k - n + question * 2
	result = ''
	for (a, b) in zip(regex[:-1], regex[1:]):
		if a != '?':
			if b == '?' and keep:
				result += a
				keep -= 1
			elif b != '?':
				result += a
	if regex[-1] != '?':
		result += regex[-1]
	print(result)


a = input()
k = int(input())
lo = 0
hi = 0
for x in a:
	if '?' == x:
		lo -= 1
	elif '*' == x:
		lo -= 1
		hi += 1000
	else:
		lo += 1
		hi += 1
if lo > k or hi < k:
	print('Impossible')
else:
	b = []
	y = ''
	for x in a:
		if '?' == x:
			b.pop()
			if lo < k:
				b += (y,)
				lo += 1
		elif '*' == x:
			b.pop()
			if lo < k:
				b += [y] * (k - lo)
				lo = k
		else:
			b += (x,)
			y = x
	print(''.join(b))


t = input().strip()
n = int(input())
(a, b) = (t.count('?'), t.count('*'))
l = len(t) - a - b
if l - a - b > n:
	print('Impossible')
	exit()
if b == 0 and l < n:
	print('Impossible')
	exit()
r = ''
if n > l:
	x = n - l
	for i in range(len(t)):
		if t[i] == '*' and x > 0:
			r += t[i - 1] * x
			x = 0
		elif t[i] not in '*?':
			r += t[i]
else:
	x = l - n
	for i in range(len(t)):
		if t[i] in '*?' and x > 0:
			r = r[:-1]
			x -= 1
		elif not t[i] in '*?':
			r += t[i]
print(r)


from collections import Counter
s = input()
k = int(input())
n = len(s)
count = Counter(s)
ques = count['?']
star = count['*']
if n - ques - star == k:
	for i in s:
		if i == '?' or i == '*':
			continue
		print(i, end='')
	print()
elif n - ques - star < k:
	diff = k - (n - ques - star)
	strr = ''
	prev = ''
	for i in s:
		if i == '*' and diff > 0:
			strr += prev * diff
			diff = 0
		if i == '*' or i == '?':
			continue
		strr += i
		prev = i
	if len(strr) == k:
		print(strr)
	else:
		print('Impossible')
else:
	diff = n - ques - star - k
	l = []
	for i in s:
		if diff > 0 and (i == '*' or i == '?'):
			diff -= 1
			del l[-1]
			continue
		if i == '*' or i == '?':
			continue
		l.append(i)
	if len(l) != k:
		print('Impossible')
	else:
		print(''.join(l))


from sys import exit
a = input()
k = int(input())
le = len(a)
cov = a.count('?')
coz = a.count('*')
leco = le - cov - coz
if leco < k and coz == 0:
	print('Impossible')
	exit(0)
if leco > k and coz + cov < leco - k:
	print('Impossible')
	exit(0)
c = 0
if leco < k:
	for i in range(0, le):
		if a[i] != '?' and a[i] != '*':
			print(a[i], end='')
		elif a[i] == '*' and c == 0:
			print(a[i - 1] * (k - leco), end='')
			c += 1
ch = 0
if leco >= k:
	a += ' '
	for i in range(0, le):
		if (a[i + 1] == '*' or a[i + 1] == '?') and ch != leco - k:
			ch += 1
		elif a[i] != '*' and a[i] != '?':
			print(a[i], end='')


(s, k) = (input(), int(input()))
inf = 200
min_len = len(s) - 2 * (s.count('?') + s.count('*'))
max_len = inf if '*' in s else len(s) - s.count('?')
if min_len <= k <= max_len:
	if '*' in s:
		last_snowflake_index = len(s) - 1 - s[::-1].index('*')
		repeats_needed = k - (len(s) - 2 * (s.count('?') + s.count('*')) + 1)
		a = ''
		for i in range(len(s)):
			if s[i] == '?':
				a = a[:-1]
			elif s[i] == '*':
				if i < last_snowflake_index:
					a = a[:-1]
				elif repeats_needed >= 0:
					a += repeats_needed * s[i - 1]
				else:
					a = a[:-1]
			else:
				a += s[i]
		print(a)
	else:
		removes_needed = len(s) - s.count('?') - k
		a = ''
		for i in range(len(s)):
			if s[i] == '?':
				if removes_needed > 0:
					a = a[:-1]
					removes_needed -= 1
			else:
				a += s[i]
		print(a)
else:
	print('Impossible')


s = input()
k = int(input())
cques = s.count('?')
cstar = s.count('*')
mini = len(s) - 2 * cstar - 2 * cques
maxi = 200 if '*' in s else len(s) - cques
if mini <= k <= maxi:
	if k == mini:
		ans = ''
		for i in range(len(s) - 1):
			if s[i + 1] not in ['?', '*'] and s[i] not in ['?', '*']:
				ans += s[i]
		if len(ans) < k:
			ans += s[-1]
		print(ans)
	elif k > len(s) - cstar - cques:
		c = k - (len(s) - cstar - cques)
		ans = ''
		for i in range(len(s)):
			if s[i] not in ['?', '*']:
				ans += s[i]
			elif s[i] == '*' and c:
				ans += s[i - 1] * c
				c = 0
		print(ans)
	elif k > mini:
		c = k - mini
		ans = ''
		for i in range(len(s) - 1):
			if s[i] in ['?', '*']:
				continue
			elif s[i] not in ['*', '?'] and s[i + 1] not in ['*', '?']:
				ans += s[i]
			elif c and s[i + 1] in ['?', '*']:
				c -= 1
				ans += s[i]
		if len(ans) < k:
			ans += s[-1]
		print(ans)
else:
	print('Impossible')


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, OrderedDict, deque
from itertools import combinations, groupby, zip_longest, permutations
from bisect import *
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline
S = input().strip('\n')
k = int(input().strip('\n'))
(candy, flakes, ch) = (0, 0, 0)
for i in S:
	if i == '?':
		candy += 1
	elif i == '*':
		flakes += 1
	else:
		ch += 1
if k == ch:
	print(''.join([i for i in S if i.islower()]))
else:
	K = k
	if k < ch:
		res = []
		removes = ch - k
		for i in S:
			if removes > 0:
				if i == '?' or i == '*':
					if res:
						res.pop()
						removes -= 1
				else:
					res.append(i)
			elif i.islower():
				res.append(i)
		res = ''.join(res)
	else:
		res = ''
		K = k
		for i in S:
			if i.islower():
				k -= 1
				res += i
			elif i == '?':
				candy -= 1
			else:
				if flakes == 1:
					if res:
						res += res[-1] * (k - (ch - len(res)))
				flakes -= 1
	if len(res) == K:
		print(res)
	else:
		print('Impossible')
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


s = input().rstrip()
x = list(s)
n = int(input())
l = []
q = []
S = []
w = []
D = []
for i in range(0, len(x)):
	if x[i].isalpha():
		l.append(x[i])
	elif x[i] == '?':
		l.append('0')
		q.append(x[i])
		S.append(i)
	elif x[i] == '*':
		l.append('0')
		w.append(x[i])
		D.append(i)
if len(l) - l.count('0') == n:
	for i in range(0, len(l)):
		if l[i] != '0':
			print(l[i], end='')
elif len(l) - l.count('0') > n:
	g = len(l) - l.count('0') - n
	if len(q) >= g or len(w) >= g or len(q) + len(w) >= g:
		k = 0
		flag = 0
		a = 0
		while k < len(q):
			t = S[k]
			if t != 0:
				l[t - 1] = '0'
				a += 1
				if a == g or len(l) - l.count('0') == n:
					flag = 1
					break
			k += 1
		if flag == 0:
			k = 0
			while k < len(w):
				t = D[k]
				if t != 0:
					l[t - 1] = '0'
					a += 1
					if a == g or len(l) - l.count('0') == n:
						break
				k += 1
		if len(l) - l.count('0') == n:
			for i in range(0, len(l)):
				if l[i] != '0':
					print(l[i], end='')
		else:
			print('Impossible')
	else:
		print('Impossible')
else:
	g = n - len(l) + l.count('0')
	k = 0
	X = 0
	while k < len(w):
		t = D[k]
		if t != 0:
			for i in range(0, g):
				l.insert(t + X, x[t - 1])
		if len(l) - l.count('0') == n:
			break
	if len(l) - l.count('0') == n:
		for i in range(0, len(l)):
			if l[i] != '0':
				print(l[i], end='')
	else:
		print('Impossible')


import math
giv = input()
k = int(input())
bound = len(giv)
snow = 0
candy = 0
oril = 0
ans = ''
for i in range(bound):
	if giv[i] == '*':
		snow += 1
	elif giv[i] == '?':
		candy += 1
	else:
		oril += 1
if oril == k:
	for i in range(bound):
		if giv[i] != '*' and giv[i] != '?':
			ans += giv[i]
elif oril > k:
	maxred = snow + candy
	if oril - k > maxred:
		ans = -1
	else:
		remd = 0
		for i in range(bound - 1):
			if remd < oril - k:
				if giv[i + 1] == '*' or giv[i + 1] == '?':
					remd += 1
				elif giv[i] != '*' and giv[i] != '?':
					ans += giv[i]
			elif giv[i] != '*' and giv[i] != '?':
				ans += giv[i]
		if giv[bound - 1] != '*' and giv[bound - 1] != '?':
			ans += giv[bound - 1]
elif snow == 0:
	ans = -1
else:
	flag = False
	for i in range(bound):
		if flag == False:
			if giv[i] != '*' and giv[i] != '?':
				ans += giv[i]
			if giv[i] == '*':
				diff = k - oril
				for j in range(diff):
					ans += giv[i - 1]
					flag = True
		elif giv[i] != '*' and giv[i] != '?':
			ans += giv[i]
if ans == -1:
	print('Impossible')
else:
	print(ans)


import re

def get_string(s, k):
	s = list(s)
	min_length = len(s) - 2 * len(list([1 for c in s if c in ('?', '*')]))
	if min_length > k:
		return 'Impossible'
	if min_length < k:
		pos = 0
		for i in range(min_length, k):
			while pos < len(s) and s[pos] not in ('?', '*'):
				pos += 1
			if pos == len(s):
				return 'Impossible'
			if s[pos] == '?':
				del s[pos]
			elif s[pos] == '*':
				s[pos:pos + 1] = [s[pos - 1]] * (k - i - 1)
				break
	return re.sub('[a-z]\\?|[a-z]\\*', '', ''.join(s))
s = input().strip()
k = int(input())
print(get_string(s, k))


snow = set()
candy = set()

def printSnow(s, k):
	cnt = 0
	encountered = False
	s2 = ''
	for i in range(1, len(s)):
		if s[i] == '*':
			if encountered == False:
				encountered = True
				s2 += s[i - 1]
				s2 += '*'
		elif s[i] not in ['?', '*'] and s[i - 1] not in ['?', '*']:
			s2 += s[i - 1]
	if s[-1] not in ['?', '*']:
		s2 += s[-1]
	s3 = ''
	min_len = len(s2) - 2
	num_to_add = k - min_len
	for i in range(1, len(s2)):
		if s2[i] == '*':
			for j in range(num_to_add):
				s3 += s2[i - 1]
		elif s2[i - 1] != '*':
			s3 += s2[i - 1]
	if s2[-1] != '*':
		s3 += s2[-1]
	return s3

def printCandy(s, k):
	len_s = len(s)
	min_len = len_s - 2 * len(candy)
	max_len = len_s - len(candy)
	keep = k - min_len
	s2 = ''
	for i in range(1, len(s)):
		if s[i] == '?' and keep:
			s2 += s[i - 1]
			keep -= 1
		elif s[i] != '?' and s[i - 1] != '?':
			s2 += s[i - 1]
	if s[-1] != '?':
		s2 += s[-1]
	return s2

def solve(s, k):
	s_len = len(s)
	for i in range(s_len):
		if s[i] == '?':
			candy.add(i)
		if s[i] == '*':
			snow.add(i)
	minl = s_len - 2 * len(snow) - 2 * len(candy)
	if minl > k:
		return 'Impossible'
	if len(snow):
		return printSnow(s, k)
	maxl = s_len - len(candy)
	if maxl < k:
		return 'Impossible'
	return printCandy(s, k)
s = input()
k = int(input())
print(solve(s, k))


s = input()
k = int(input())
(candy, flake) = (0, 0)
N = len(s)
t = ''
for i in range(N):
	if s[i] == '?':
		candy += 1
	elif s[i] == '*':
		flake += 1
if N - 2 * (candy + flake) > k:
	print('Impossible')
elif N - (candy + flake) >= k:
	m = N - (candy + flake)
	for i in range(N):
		if i + 1 < N and m > k and (s[i + 1] == '?' or s[i + 1] == '*'):
			m -= 1
		elif i + 1 < N and (s[i + 1] == '?' or s[i + 1] == '*'):
			t += s[i]
		elif s[i] != '?' and s[i] != '*':
			t += s[i]
	print(t)
elif flake == 0:
	print('Impossible')
else:
	flag = True
	for i in range(N):
		if i + 1 < N and flag and (s[i + 1] == '*'):
			t += (k - (N - (candy + flake)) + 1) * s[i]
			flag = False
		elif i + 1 < N and (s[i + 1] == '?' or s[i + 1] == '*'):
			t += s[i]
		elif s[i] != '?' and s[i] != '*':
			t += s[i]
	print(t)


s = input()
x = int(input())
if '*' not in s:
	if len(s) - s.count('?') < x or len(s) - s.count('?') * 2 > x:
		print('Impossible')
	else:
		need = len(s) - s.count('?') - x
		i = 0
		while i < len(s):
			if s[i] == '?':
				if need != 0:
					s = s[:i - 1] + s[i + 1:]
					need -= 1
					i -= 1
				else:
					s = s[:i] + s[i + 1:]
					i -= 1
			else:
				i += 1
		print(s)
elif len(s) - (s.count('?') + s.count('*')) * 2 > x:
	print('Impossible')
else:
	i = 0
	cnt = s.count('*')
	while i < len(s):
		if s[i] == '?':
			s = s[:i - 1] + s[i + 1:]
			i -= 1
		elif s[i] == '*':
			if cnt != 1:
				s = s[:i - 1] + s[i + 1:]
				cnt -= 1
				i -= 1
			else:
				i += 1
		else:
			i += 1
	need = x - (len(s) - 1) + 1
	ind = s.index('*')
	s = s[:ind - 1] + s[ind - 1] * need + s[ind + 1:]
	print(s)


s = input()
k = int(input())
j = 0
for i in s:
	if i != '?' and i != '*':
		j += 1
a = []
if j == k:
	for i in s:
		if i != '?' and i != '*':
			a.append(i)
if j > k:
	for i in s:
		if i == '?' or i == '*':
			if j > k and len(a) > 0:
				j -= 1
				a.pop()
		if i != '?' and i != '*':
			a.append(i)
if k > j:
	for i in s:
		if i == '*':
			if k > j and len(a) > 0:
				f = k - j
				for _ in range(f):
					a.append(a[-1])
				j = k
		if i != '?' and i != '*':
			a.append(i)
if len(a) != k:
	print('Impossible')
else:
	print(*a, sep='')


s = input()
k = int(input())
n = len(s)
(ans, ind) = ('', False)
count = 0
for i in range(n):
	if s[i] != '?' and s[i] != '*':
		count += 1
if count == k:
	for i in range(n):
		if s[i] != '?' and s[i] != '*':
			ans += s[i]
	print(ans)
elif count > k:
	ans = []
	for i in range(n):
		if s[i] != '?' and s[i] != '*':
			ans.append(s[i])
		elif s[i] == '?' or s[i] == '*':
			count1 = 0
			for j in range(i + 1, n):
				if s[j] != '?' and s[j] != '*':
					count1 += 1
			if len(ans) + count1 > k:
				ans.pop()
	if len(ans) == k:
		res = ''
		for i in ans:
			res += i
		print(res)
	else:
		print('Impossible')
elif count < k:
	ans = []
	for i in range(n):
		if s[i] != '?' and s[i] != '*':
			ans.append(s[i])
		elif s[i] == '*' and (not ind):
			ind = True
			for j in range(k - count):
				ans.append(s[i - 1])
	res = ''
	if len(ans) == k:
		for i in ans:
			res += i
		print(res)
	else:
		print('Impossible')


s = input()
k = int(input())
res = []
rem = []
rep = -1
for c in s:
	if c != '?' and c != '*':
		res.append(c)
	else:
		rem.append(len(res) - 1)
	if c == '*':
		rep = len(res) - 1
if len(res) > k:
	d = len(res) - k
	if d > len(rem):
		print('Impossible')
	else:
		for r_i in reversed(rem):
			del res[r_i]
			d -= 1
			if d == 0:
				break
		print(''.join(res))
elif len(res) < k:
	if rep < 0:
		print('Impossible')
	else:
		res[rep] = res[rep] * (k - len(res) + 1)
		print(''.join(res))
else:
	print(''.join(res))


s = input()
k = int(input())
lenght = 0
answer = ''
for i in range(len(s)):
	if s[i] != '*' and s[i] != '?':
		lenght += 1
if lenght == k:
	for i in range(len(s)):
		if s[i] != '*' and s[i] != '?':
			answer += s[i]
elif lenght > k:
	for i in range(len(s)):
		if i - 1 > -1 and s[i] == '*' or s[i] == '?':
			if lenght > k:
				answer = answer[:-1]
				lenght -= 1
		elif s[i] != '*' and s[i] != '?':
			answer += s[i]
else:
	for i in range(len(s)):
		if i - 1 > -1 and s[i] == '*':
			if lenght < k:
				answer = answer[:-1] + answer[-1] * (k - lenght + 1)
				lenght += k - lenght
		elif s[i] != '?':
			answer += s[i]
if len(answer) != k:
	print('Impossible')
else:
	print(answer)


s = input()
k = int(input())
sPos = []
cPos = []
chars = []
for i in range(len(s)):
	if s[i] == '*':
		sPos.append(i)
	elif s[i] == '?':
		cPos.append(i)
(minL, maxL) = (None, None)
if len(sPos) != 0:
	maxL = 200
else:
	maxL = len(s) - len(cPos)
minL = len(s) - 2 * (len(cPos) + len(sPos))
if k < minL or k > maxL:
	print('Impossible')
else:
	curL = len(s) - len(cPos) - len(sPos)
	s = list(s)
	curDiff = curL - k
	while curDiff != 0:
		for i in range(len(s)):
			if s[i] == '*':
				if curDiff > 0:
					s[i - 1] = ''
					s[i] = ''
					curDiff -= 1
				else:
					s[i] = s[i - 1] * (0 - curDiff)
					curDiff = 0
			elif s[i] == '?':
				if curDiff > 0:
					s[i - 1] = ''
					s[i] = ''
					curDiff -= 1
				else:
					s[i] = ''
			if curDiff == 0:
				break
	for i in range(len(s)):
		if s[i] == '*' or s[i] == '?':
			s[i] = ''
	ans = ''.join(s)
	print(ans)


st = input()
k = int(input())
L = 0
for ch in st:
	if ch not in ['*', '?']:
		L += 1
if L > k:
	s = []
	edit = L - k
	if len(st) - L < edit:
		print('Impossible')
		exit()
	i = 0
	while i < len(st):
		if st[i] in ['*', '?']:
			if edit > 0:
				s.pop()
				edit -= 1
		else:
			s.append(st[i])
		i += 1
	print(''.join(s))
elif L < k:
	s = []
	edit = k - L
	pos = -1
	flag = False
	for i in range(len(st)):
		if st[i] != '?':
			if st[i] == '*':
				flag = True
			else:
				s.append(st[i])
				if not flag:
					pos += 1
	if flag:
		s = s[0:pos] + [s[pos]] * edit + s[pos:]
		print(''.join(s))
	else:
		print('Impossible')
		exit()
else:
	s = ''
	for ch in st:
		if ch not in ['?', '*']:
			s += ch
	print(s)


s = input()
n = int(input())
(candy, snow) = ([], [])
compressed = ''
res = ''
for i in range(len(s)):
	if s[i] == '?':
		candy.append((s[i - 1], i - 2 * len(candy) - 2 * len(snow) - 1))
		compressed = compressed[:-1]
	elif s[i] == '*':
		snow.append((s[i - 1], i - 2 * len(candy) - 2 * len(snow) - 1))
		compressed = compressed[:-1]
	else:
		compressed += s[i]
if len(compressed) > n:
	print('Impossible')
elif len(compressed) == n:
	print(compressed)
elif len(snow) != 0:
	idx = snow[0][1]
	res = compressed[:idx] + snow[0][0] * (n - len(compressed)) + compressed[idx:]
	print(res)
elif len(compressed) + len(candy) < n:
	print('Impossible')
else:
	delta = n - len(compressed)
	for i in range(delta):
		if i == 0:
			res = compressed[:candy[i][1]] + candy[i][0] + compressed[candy[i][1]:]
		else:
			res = res[:candy[i][1] + i] + candy[i][0] + res[candy[i][1] + i:]
	print(res)


s = input()
t = int(input())
total = 0
len_string = len(s)
repeat = 0
for i in s:
	if i == '?' or i == '*':
		total += 1
	if i == '*':
		repeat += 1
rem_string = len_string - total
if t < rem_string - total:
	print('Impossible')
elif t == rem_string:
	result = ''
	for i in s:
		if i != '?' and i != '*':
			result += i
	print(result)
else:
	result = ''
	if t > rem_string and repeat > 0:
		result = ''
		flag = -1
		index = len(s) + 1
		for i in range(len(s)):
			if s[i] != '?' and s[i] != '*':
				result += s[i]
			elif s[i] == '*':
				value = t - rem_string
				for j in range(value):
					result += s[i - 1]
				index = i + 1
				flag = 1
			if flag == 1:
				break
		for j in range(index, len(s)):
			if s[j] != '?' and s[j] != '*':
				result += s[j]
		print(result)
	elif t > rem_string and repeat == 0:
		print('Impossible')
	else:
		result = []
		index = len(s) + 1
		count = 0
		for i in range(len(s)):
			if s[i] != '?' and s[i] != '*':
				result.append(s[i])
			elif s[i] == '?' or s[i] == '*':
				count += 1
				del result[-1]
			if count == rem_string - t:
				index = i + 1
				break
		for j in range(index, len(s)):
			if s[j] != '?' and s[j] != '*':
				result.append(s[j])
		result_string = ''
		for i in result:
			result_string += i
		print(result_string)


s = input()
k = int(input())
parsed = []
i = 0
while i < len(s):
	c = s[i]
	op = ''
	if i + 1 < len(s):
		cnext = s[i + 1]
		if cnext in {'?', '*'}:
			op = cnext
			i = i + 1
	parsed.append((c, op))
	i = i + 1
min_l = sum((1 for (_, op) in parsed if op == ''))
max_l = 201 if any((op == '*' for (_, op) in parsed)) else len(parsed)
if min_l <= k <= max_l:
	num_quest = sum((1 for (_, op) in parsed if op == '?'))
	quests_to_use = min(num_quest, k - min_l)
	star_nums = k - quests_to_use - min_l
	for (c, op) in parsed:
		if op == '':
			print(c, end='')
		elif op == '?':
			if quests_to_use > 0:
				print(c, end='')
				quests_to_use -= 1
		elif star_nums:
			print(c * star_nums, end='')
			star_nums = 0
	print()
else:
	print('Impossible')


s = [i for i in input()]
k = int(input())
snow = []
candy = []
good = []
for i in range(len(s)):
	if s[i] == '*':
		snow.append(i)
	elif s[i] == '?':
		candy.append(i)
	else:
		good.append(i)
P = []
count = 0
while count < len(s) - 1:
	if s[count + 1] == '*' or s[count + 1] == '?':
		P.append((s[count], s[count + 1]))
		count += 2
	else:
		P.append(s[count])
		count += 1
if s[-1] != '*' and s[-1] != '?':
	P.append(s[-1])
if len(snow) > 0:
	for j in range(len(P)):
		if len(P[j]) >= 2:
			if P[j][1] == '*':
				firsts = j
				break
	smallest = len(good) - len(snow) - len(candy)
	if k >= smallest:
		if k > len(good):
			for i in range(len(P)):
				if i == firsts:
					print(P[i][0] * (k - len(good) + 1), end='')
				else:
					print(P[i][0], end='')
		else:
			delete = len(good) - k
			for i in range(len(P)):
				if delete > 0:
					if len(P[i]) == 2:
						delete -= 1
					else:
						print(P[i][0], end='')
				else:
					print(P[i][0], end='')
	else:
		print('Impossible')
else:
	smallest = len(good) - len(snow) - len(candy)
	largest = len(good)
	if smallest <= k and largest >= k:
		delete = len(good) - k
		for i in range(len(P)):
			if delete > 0:
				if len(P[i]) == 2:
					delete -= 1
				else:
					print(P[i][0], end='')
			else:
				print(P[i][0], end='')
	else:
		print('Impossible')


import string
s = input()
k = int(input())

def find_valid_characters(s):
	valid_count = 0
	for el in s:
		if el in string.ascii_lowercase:
			valid_count += 1
	return valid_count
valid_count = find_valid_characters(s)
res = []
if valid_count == k:
	for el in s:
		if el in string.ascii_lowercase:
			res.append(el)
elif valid_count > k:
	deleted = set()
	for i in range(len(s)):
		if s[i] == '?' or s[i] == '*':
			deleted.add(i - 1)
			valid_count -= 1
		if valid_count == k:
			break
	if valid_count != k:
		print('Impossible')
		exit(0)
	else:
		for i in range(len(s)):
			if i not in deleted and s[i] in string.ascii_lowercase:
				res.append(s[i])
else:
	star_pos = None
	for i in range(len(s)):
		if s[i] == '*':
			star_pos = i - 1
			break
	if star_pos is None:
		print('Impossible')
		exit(0)
	res = []
	for i in range(len(s)):
		if i == star_pos:
			res.extend(list(s[i] * (k - valid_count + 1)))
		elif s[i] in string.ascii_lowercase:
			res.append(s[i])
print(''.join(res))


s = input()
k = int(input())
c = 0
p = 0
has_star = False
for i in range(len(s)):
	if s[i] in ['*', '?']:
		if s[i] == '*':
			has_star = True
		c -= 1
	else:
		p += 1
		c += 1
if k < c:
	print('Impossible')
elif not has_star and k > p:
	print('Impossible')
else:
	signs_to_add = k - c
	ans = ''
	for i in s:
		if signs_to_add == 0:
			if i not in ['*', '?']:
				ans += i
			else:
				ans = ans[:-1]
			continue
		if i == '?':
			signs_to_add -= 1
		elif i == '*':
			signs_to_add -= 1
			while signs_to_add > 0:
				ans += ans[-1]
				signs_to_add -= 1
		else:
			ans += i
	print(ans)


s = input()
k = int(input())
minlen = 0
maxlen = 0
for i in s:
	if i != '?' and i != '*':
		maxlen += 1
		minlen += 1
	else:
		minlen -= 1
ans = []
q = True
cou = k - minlen
if minlen > k:
	print('Impossible')
	exit()
if '*' in s:
	for i in range(len(s)):
		if s[i] == '?':
			ans.pop()
		elif s[i] == '*':
			if q:
				ans.pop()
				q = False
				for j in range(cou):
					ans.append(s[i - 1])
			else:
				ans.pop()
		else:
			ans.append(s[i])
else:
	if maxlen < k:
		print('Impossible')
		exit()
	for i in range(len(s)):
		if s[i] == '?':
			if cou:
				cou -= 1
			else:
				ans.pop()
		else:
			ans.append(s[i])
print(*ans, sep='')


message = input()
n = int(input())
cleanmsg = ''
sfinsert = []
insertionlt = []
cc = message.count('?')
sf = message.count('*')
if sf == 0 and cc > 0:
	left = len(message) - 2 * cc
	r = ''
	occrecord = []
	if left == n:
		r1 = ''
		for o in range(len(message) - 1):
			if message[o] != '?' and message[o + 1] != '?':
				r1 += message[o]
		if message[-1] != '?':
			r1 += message[-1]
		print(r1)
		exit()
	if left > n or left + cc < n:
		print('Impossible')
		exit()
	occleft = n - left
	if len(message) - cc == n:
		print(message.replace('?', ''))
		exit()
	for occ in range(len(message) - 1):
		if occleft > 0:
			if message[occ] != '?':
				r += message[occ]
			if message[occ] != '?' and message[occ + 1] == '?':
				occleft -= 1
		if occleft <= 0:
			if message[occ] != '?' and message[occ + 1] != '?':
				r += message[occ]
	if message[-1] != '?':
		r += message[-1]
	print(r)
	exit()
for unf in range(len(message) - 1):
	if message[unf] != '?' and message[unf] != '*' and (message[unf + 1] != '?') and (message[unf + 1] != '*'):
		cleanmsg += message[unf]
	if message[unf + 1] == '*':
		sfinsert.append(len(cleanmsg))
		insertionlt.append(message[unf])
if message[-1] != '?' and message[-1] != '*':
	cleanmsg += message[-1]
if len(cleanmsg) == n:
	print(cleanmsg)
	exit()
if len(cleanmsg) > n or (len(cleanmsg) < n and len(sfinsert) == 0):
	print('Impossible')
	exit()
left = n - len(cleanmsg)
res = cleanmsg[:sfinsert[0]] + insertionlt[0] * left + cleanmsg[sfinsert[0]:]
print(res)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
s = input()
k = iinput()
n = len(s)
cc = s.count('?')
sf = s.count('*')
if cc == 0 and sf == 0:
	if n == k:
		print(s)
	else:
		print('Impossible')
elif n - 2 * (cc + sf) > k:
	print('Impossible')
elif n - (cc + sf) == k:
	ans = s.replace('*', '').replace('?', '')
	print(ans)
elif sf == 0:
	if k < n - 2 * cc or k > n - cc:
		print('Impossible')
		exit()
	else:
		toDelete = n - cc - k
		ans = ''
		i = cnt = 0
		while cnt < toDelete:
			if i < n - 1 and s[i + 1] == '?':
				i += 2
				cnt += 1
			else:
				ans += s[i]
				i += 1
		ans += s[i:].replace('?', '')
		print(ans)
else:
	ans = ''
	stop = 0
	for i in range(n - 1):
		if s[i] == '?' or s[i + 1] == '?' or s[i] == '*':
			continue
		elif s[i + 1] == '*':
			if stop == 0:
				stop = 1
				ans += s[i] + s[i + 1]
		else:
			ans += s[i]
	ans += s[-1].replace('?', '').replace('*', '')
	toAdd = k - (len(ans) - 1)
	ind = ans.index('*')
	if toAdd < 0:
		toDelete = abs(toAdd)
		ans2 = ''
		ans = ans.replace('*', '?')
		i = cnt = 0
		n = len(ans)
		while cnt < toDelete:
			if i < n - 1 and ans[i + 1] == '?':
				i += 2
				cnt += 1
			else:
				ans2 += ans[i]
				i += 1
		ans2 += ans[i:].replace('?', '')
		print(ans2)
	else:
		ans = ans[:ind] + ans[ind - 1] * toAdd + ans[ind + 1:]
		print(ans)


from collections import Counter
s = input()
k = int(input())
counts = Counter(s)
s_cnt = counts['*']
q_cnt = counts['?']
l_cnt = len(s) - 2 * (s_cnt + q_cnt)

def solve():
	if l_cnt > k:
		return 'Impossible'
	t = k - l_cnt
	if q_cnt < t and s_cnt == 0:
		return 'Impossible'
	q_t = min(q_cnt, t)
	s_t = t - q_t if s_cnt > 0 else 0
	res = []
	for i in range(len(s)):
		if s[i] in ('*', '?'):
			continue
		elif i < len(s) - 1 and s[i + 1] == '?' and (q_t > 0):
			res.append(s[i])
			q_t -= 1
		elif i < len(s) - 1 and s[i + 1] == '*' and (s_t > 0):
			for j in range(s_t):
				res.append(s[i])
			s_t = 0
		elif i + 1 == len(s) or s[i + 1] not in ('*', '?'):
			res.append(s[i])
	return ''.join(res)
sol = solve()
print(sol)


s = list(input())
k = int(input())
l = len(s)
a = s.count('?') + s.count('*')
s += ['#']
if k >= l - a:
	ans = ''
	c = 0
	las = ''
	de = k - (l - a)
	for i in range(l - 1, -1, -1):
		if s[i] != '?' and s[i] != '*' and (s[i + 1] == '*') and (c == 0):
			ans += s[i] * (de + 1)
			c += 1
		elif s[i] != '?' and s[i] != '*' and (s[i] != '#'):
			ans += s[i]
	if len(ans) == k:
		print(ans[::-1])
	else:
		print('Impossible')
else:
	de = l - a - k
	ans = ''
	c = 0
	for i in range(l - 1, -1, -1):
		if s[i] != '?' and s[i] != '*' and (s[i + 1] == '?' or s[i + 1] == '*') and (c != de):
			c += 1
		elif s[i] != '?' and s[i] != '*':
			ans += s[i]
	if len(ans) == k:
		print(ans[::-1])
	else:
		print('Impossible')


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import add
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
s = ip()
n = ii()
x = len(s) - s.count('?') - s.count('*')
if x < n and s.count('*') == 0 or (x > n and s.count('*') + s.count('?') < x - n):
	print('Impossible')
	exit()
if x > n:
	arr = []
	for i in s:
		if i != '?' and i != '*':
			arr.append(i)
		elif x != n:
			arr.pop()
			x -= 1
	print(''.join(arr))
elif x < n:
	arr = []
	for i in s:
		if i == '*':
			if n >= x:
				arr.extend((n - x) * [arr[-1]])
				x = n
			else:
				break
		elif i != '?':
			arr.append(i)
	print(''.join(arr))
else:
	s = s.replace('?', '')
	s = s.replace('*', '')
	print(s)


s = input()
l = len(s)
k = int(input())
a = b = c = 0
res = ''
for i in range(l):
	if s[i] == '*':
		a += 1
	elif s[i] == '?':
		b += 1
	else:
		c += 1
if k == c:
	for i in range(l):
		if s[i] not in '?*':
			print(s[i], end='')
elif c > k:
	yy = c - k
	if yy > a + b:
		print('Impossible')
	else:
		ans = ''
		f = 0
		for i in range(l - 1, -1, -1):
			if s[i] == '?' or s[i] == '*':
				f = 1
			elif f == 1 and yy > 0:
				yy -= 1
				f = 0
			else:
				f = 0
				ans += s[i]
		print(ans[::-1])
else:
	yy = k - c
	if a == 0:
		print('Impossible')
	else:
		ans = ''
		f = 0
		for i in range(l):
			if f == 0 and s[i] == '*':
				f = 1
				ans += s[i - 1] * yy
			elif s[i] not in '*?':
				ans += s[i]
		print(ans)


string = str(input())
k = int(input())
count_of_symbols = 0
max_sym_to_delete = 0
snowflake = False
lng = len(string)
new_string = ''
for i in range(lng):
	if string[i] == '*':
		snowflake = True
		max_sym_to_delete += 1
	if string[i] == '?':
		max_sym_to_delete += 1
	if string[i] != '?' and string[i] != '*':
		count_of_symbols += 1
if count_of_symbols == k:
	for i in range(lng):
		if string[i] != '?' and string[i] != '*':
			new_string += string[i]
	print(new_string)
	exit(0)
if count_of_symbols - max_sym_to_delete <= k < count_of_symbols:
	sum_to_del = count_of_symbols - k
	counter = 0
	for i in range(lng):
		if counter < sum_to_del:
			if string[i] != '?' and string[i] != '*':
				if i < lng - 1:
					if string[i + 1] == '*' or string[i + 1] == '?':
						counter += 1
						continue
		if string[i] != '?' and string[i] != '*':
			if i < lng - 1:
				if (string[i + 1] != '*' or string[i + 1] != '?') or counter == sum_to_del:
					new_string += string[i]
			elif string[i] != '?' and string[i] != '*':
				new_string += string[i]
	print(new_string)
	exit(0)
if count_of_symbols < k and snowflake:
	sym_to_add = k - count_of_symbols
	pass_the_sym_add = True
	for i in range(lng):
		if i < lng - 1:
			if string[i + 1] == '*':
				if pass_the_sym_add:
					pass_the_sym_add = False
					new_string += string[i] * sym_to_add
		if string[i] != '*' and string[i] != '?':
			if i < lng - 1:
				if string[i + 1] != '*' or not pass_the_sym_add:
					new_string += string[i]
			elif string[i] != '?' and string[i] != '*':
				new_string += string[i]
	print(new_string)
	exit(0)
else:
	print('Impossible')
	exit(0)


import math
s = input()
n = int(input())
candy = 0
snow = 0
letter = 0
for c in s:
	if c == '?':
		candy += 1
	elif c == '*':
		snow += 1
	else:
		letter += 1
if n < letter - candy - snow or (letter < n and snow == 0):
	print('Impossible')
else:
	res = ''
	if letter < n:
		need = n - letter
		first = True
		for i in range(len(s)):
			if i + 1 < len(s) and s[i + 1] == '*' and first:
				first = False
				for n in range(need + 1):
					res += s[i]
			elif s[i] != '?' and s[i] != '*':
				res += s[i]
	else:
		dele = letter - n
		i = 0
		while i < len(s):
			if i + 1 < len(s) and (s[i + 1] == '?' or s[i + 1] == '*') and (dele > 0):
				dele -= 1
				i += 1
			elif s[i] != '?' and s[i] != '*':
				res += s[i]
			i += 1
	print(res)


string = input()
length = int(input())
tt = [True] * len(string)
candy = []
snowflake = []
total = len(string)
tttt = ['?', '*']
import sys
for i in range(len(string)):
	if string[i] == '?':
		candy.append(i)
		tt[i] = False
		total -= 1
	elif string[i] == '*':
		if len(snowflake) is 0:
			snowflake.append(i)
		else:
			candy.append(i)
		tt[i] = False
		total -= 1
if length > total:
	if len(snowflake) == 0:
		print('Impossible')
	else:
		snow_string = string[snowflake[0] - 1] * (length - total)
		for i in range(snowflake[0]):
			if tt[i]:
				sys.stdout.write(string[i])
		sys.stdout.write(snow_string)
		for i in range(snowflake[0], len(string)):
			if tt[i]:
				sys.stdout.write(string[i])
elif total - len(snowflake) - len(candy) > length:
	print('Impossible')
else:
	if len(snowflake) is not 0:
		candy.append(snowflake[0])
	rrr = total - length
	for i in range(rrr):
		tt[candy[i] - 1] = False
	for i in range(len(string)):
		if tt[i]:
			sys.stdout.write(string[i])


line = input()
k = int(input())
minl = 0
maxl = 0
que = line.count('?')
zv = line.count('*')
b = len(line) - zv - que
for i in range(len(line)):
	if line[i] == '*':
		maxl = 201
		minl -= 1
	elif line[i] == '?':
		minl -= 1
	else:
		minl += 1
		maxl = maxl + 1
nw = ''
if minl <= k <= maxl:
	if zv > 0:
		need = k - (b - que)
		for i in range(len(line)):
			if line[i] == '?':
				nw = nw[:len(nw) - 1]
			elif line[i] == '*':
				if need > 0:
					nw += line[i - 1] * need
					need = 0
				elif need < 0:
					need += 1
					nw = nw[:len(nw) - 1]
			else:
				nw += line[i]
	else:
		dl = b - k
		for i in range(len(line)):
			if line[i] == '?':
				if dl > 0:
					nw = nw[:len(nw) - 1]
					dl -= 1
			else:
				nw += line[i]
	print(nw)
else:
	print('Impossible')


s = input()
k = int(input())
lolly = 0
snow = 0
l = 0
ans = ''
for i in s:
	if i == '?':
		lolly += 1
	elif i == '*':
		snow += 1
	else:
		l += 1
if l < k and snow == 0:
	print('Impossible')
elif l < k and snow > 0:
	for j in range(len(s)):
		if s[j] != '?' and s[j] != '*':
			if j + 1 < len(s) and s[j + 1] == '*':
				ans += s[j] * (k - l + 1)
				k = l
			else:
				ans += s[j]
	print(ans)
elif l == k:
	for j in range(len(s)):
		if s[j] != '?' and s[j] != '*':
			ans += s[j]
	print(ans)
elif l > k:
	if lolly + snow >= l - k:
		p = l - k
		for j in range(len(s)):
			if s[j] != '?' and s[j] != '*':
				if p > 0:
					if j + 1 < len(s) and (s[j + 1] == '*' or s[j + 1] == '?'):
						p -= 1
					else:
						ans += s[j]
				else:
					ans += s[j]
		print(ans)
	else:
		print('Impossible')


S = list(input())
K = int(input())
S2 = []
for i in range(len(S)):
	if S[i] == '?' or S[i] == '*':
		S2[i - 1] = ''
		S2.append('')
	else:
		S2.append(S[i])
ln = len(''.join(S2))
if K < ln:
	print('Impossible')
	exit()
for i in range(len(S2)):
	if K == ln:
		print(''.join(S2))
		exit()
	if S[i] == '*':
		S2[i - 1] = S[i - 1] * (K - ln)
		print(''.join(S2))
		exit()
	if S[i] == '?':
		S2[i - 1] = S[i - 1]
		ln += 1
if K == ln:
	print(''.join(S2))
else:
	print('Impossible')


a = input()
b = int(input())
k = a.count('*')
k1 = a.count('?')
z = len(a) - k - k1
if z - b == 0:
	a = a.replace('?', '').replace('*', '')
	for i in a:
		print(i, end='')
elif z - b > 0:
	if z - b <= k + k1:
		f = z - b
		i = 0
		a = a.replace('', ' ').split()
		while f != 0:
			if '*' in a:
				s = a.index('*')
				a.pop(s)
				a.pop(s - 1)
			else:
				s = a.index('?')
				a.pop(s)
				a.pop(s - 1)
			f -= 1
		for j in a:
			if j not in '?*':
				print(j, end='')
	else:
		print('Impossible')
elif '*' not in a:
	print('Impossible')
else:
	s = b - z
	for i in range(len(a)):
		if a[i] not in '?*':
			print(a[i], end='')
		elif a[i] == '*':
			while s:
				print(a[i - 1], end='')
				s -= 1


import re

def f(cs):
	global x
	if x < 0:
		x += 1
		return ''
	elif x > 0 and cs[0][1] == '*':
		(t, x) = (x + 1, 0)
		return cs[0][0] * t
	else:
		return cs[0][0]
s = input()
x = int(input()) + s.count('?') + s.count('*') - len(s)
s = re.sub('\\w[?*]', f, s)
print('Impossible' if x else s)


s = input()
n = int(input())
p = len(s)
c1 = 0
c2 = 0
k = 0
for i in range(p):
	if s[i] == '?':
		c1 += 1
	elif s[i] == '*':
		c2 += 1
	else:
		k += 1
if k == n:
	f = ''
	for i in range(p):
		if s[i] not in ['?', '*']:
			f += s[i]
	print(f)
elif k > n:
	if k - c1 - c2 > n:
		print('Impossible')
	else:
		ff = k - n
		f = ''
		kk = 0
		for j in range(p - 1):
			if s[j] not in ['?', '*'] and s[j + 1] in ['?', '*'] and (kk < ff):
				kk += 1
			elif s[j] not in ['?', '*']:
				f += s[j]
		if s[p - 1] not in ['?', '*']:
			f += s[p - 1]
		print(f)
elif k < n:
	if c2 == 0:
		print('Impossible')
	else:
		ff = n - k
		f = ''
		kk = 0
		for j in range(p - 1):
			if kk < ff and s[j + 1] == '*':
				f += s[j]
				for jj in range(ff):
					f += s[j]
					kk += 1
			elif s[j] not in ['?', '*']:
				f += s[j]
		if s[p - 1] not in ['?', '*']:
			f += s[p - 1]
		print(f)


s = input()
k = int(input())
n = s.count('*')
m = n + s.count('?')
l = len(s) - m
if k < l - m or (n == 0 and k > l):
	s = 'Impossible'
elif k > l:
	i = s.find('*')
	s = s.replace('*', s[i - 1] * (k - l), 1)
s = s.replace('*', '?')
for _ in [0] * (l - k):
	i = s.find('?')
	s = s.replace(s[i - 1] + '?', '', 1)
print(s.replace('?', ''))


str = input()
str_len = len(str) - str.count('?') - str.count('*')
k = int(input())
if k > str_len:
	if '*' not in str:
		print('Impossible')
		exit()
	ind = str.index('*')
	if ind == len(str) - 1:
		str = str[:ind] + (k - str_len) * str[ind - 1]
	else:
		str = str[:ind] + (k - str_len) * str[ind - 1] + str[ind + 1:]
	str = str.replace('?', '')
	str = str.replace('*', '')
	print(str)
	exit()
elif k < str_len:
	if str_len - k > str.count('?') + str.count('*'):
		print('Impossible')
		exit()
	new_str = ''
	del_count = str_len - k
	for i in range(len(str)):
		if str[i] in '*?':
			if del_count > 0:
				new_str = new_str[:-1]
				del_count -= 1
		else:
			new_str += str[i]
	print(new_str)
else:
	str = str.replace('?', '')
	str = str.replace('*', '')
	print(str)


chars = []
typ = []
s = input()
for c in s:
	if c == '?':
		typ[-1] = 1
	elif c == '*':
		typ[-1] = 2
	else:
		chars.append(c)
		typ.append(0)
typCount = [0, 0, 0]
for i in typ:
	typCount[i] += 1
want = int(input())
for i in range(len(chars)):
	if typCount[0] >= want:
		break
	if typ[i] == 1:
		typ[i] = 0
		typCount[0] += 1
if typCount[0] > want:
	print('Impossible')
elif typCount[2] == 0 and typCount[0] < want:
	print('Impossible')
else:
	if typCount[2] > 0:
		i = typ.index(2)
		chars[i] *= want - typCount[0]
		typ[i] = 0
	out = ''
	for i in range(len(chars)):
		if typ[i] == 0:
			out += chars[i]
	print(out)


def remove_symbols(msg):
	return list(filter(lambda x: x not in ['*', '?'], msg))
msg = list(input())
msg_wo_symbols = ''.join(remove_symbols(msg))
k = int(input())
if len(msg_wo_symbols) == k:
	print(msg_wo_symbols)
elif len(msg_wo_symbols) > k:
	for i in range(len(msg) - 1, -1, -1):
		if len(remove_symbols(msg)) == k:
			print(''.join(remove_symbols(msg)))
			break
		elif i + 1 <= len(msg) - 1 and msg[i + 1] in ['?', '*']:
			msg.pop(i + 1)
			msg.pop(i)
elif '*' in msg:
	for i in range(len(msg)):
		if msg[i] == '*':
			rpt = msg[i - 1]
			while len(remove_symbols(msg)) != k:
				msg.insert(i, rpt)
			break
	print(''.join(remove_symbols(msg)))
if len(remove_symbols(msg)) != k:
	print('Impossible')


s = input()
k = int(input())
q = ''
cc = len(s) - s.count('*') - s.count('?')
delta = k - cc
for i in range(len(s)):
	if s[i] == '*':
		if delta > 0:
			q += s[i - 1] * delta
			delta = 0
		elif delta < 0:
			q = q[:-1]
			delta += 1
	elif s[i] == '?':
		if delta < 0:
			q = q[:-1]
			delta += 1
	else:
		q += s[i]
if len(q) == k:
	print(q)
else:
	print('Impossible')


import sys
import math

def read_int():
	return int(input().strip())

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

def read_string():
	return input().strip()

def read_string_list(delim=' '):
	return input().strip().split(delim)
s = read_string()
k = read_int()
spec_len = 0
for _s in s:
	if _s in ['?', '*']:
		spec_len += 1
norm_len = len(s) - spec_len
if k < norm_len - spec_len:
	print('Impossible')
	sys.exit()
elif k <= norm_len:
	to_be_removed = norm_len - k
	out = ''
	for i in range(len(s) - 1):
		if s[i] in ['?', '*']:
			continue
		if s[i + 1] in ['?', '*']:
			if to_be_removed > 0:
				to_be_removed -= 1
				continue
			else:
				out += s[i]
		else:
			out += s[i]
	if s[len(s) - 1] not in ['?', '*'] and len(out) < k:
		out += s[len(s) - 1]
	print(out)
	sys.exit()
else:
	to_be_repeated = k - norm_len
	asterx_loc = s.find('*')
	if asterx_loc == -1:
		print('Impossible')
		sys.exit()
	out = ''
	for i in range(len(s) - 1):
		if s[i] in ['?', '*']:
			continue
		if s[i + 1] in ['*']:
			out += s[i]
			out += s[i] * to_be_repeated
			to_be_repeated = 0
		else:
			out += s[i]
	if s[len(s) - 1] in ['*'] and len(out) < k:
		out += s[len(s) - 1]
		out += s[len(s) - 1] * to_be_repeated
	elif s[len(s) - 1] not in ['?', '*']:
		out += s[len(s) - 1]
	print(out)
	sys.exit()


v1 = input()
m = list(v1)
p = len(v1)
k = int(input())
ch = 0
s_ch = 0
p_ch = 0
for i in range(p):
	if v1[i] == '?':
		s_ch = s_ch + 1
	elif v1[i] == '*':
		p_ch = p_ch + 1
	else:
		ch = ch + 1
cng = 0
if k - ch < 0:
	cng = 2
elif k - ch == 0:
	cng = 0
elif k - ch > 0:
	cng = 1
n_str = ''
if cng == 0:
	for i in range(p):
		if v1[i] == '?' or v1[i] == '*':
			mov = 1
		else:
			n_str = n_str + v1[i]
	print(n_str)
elif cng == 1:
	if p_ch == 0:
		print('Impossible')
	else:
		add = ''
		for i in range(p):
			if v1[i] == '*':
				add = v1[i - 1]
				break
		count = k - ch
		add = add * count
		shout = 0
		for i in range(p):
			if v1[i] == '*' and shout == 0:
				n_str = n_str + add
				shout = shout + 1
			elif v1[i] == '*' or v1[i] == '?':
				max_val = 1
			else:
				n_str = n_str + v1[i]
		print(n_str)
elif cng == 2:
	if ch - s_ch - p_ch > k:
		print('Impossible')
	else:
		need = ch - k
		for i in range(p):
			if (m[i] == '?' or m[i] == '*') and need > 0:
				m[i - 1] = '.'
				need = need - 1
		for i in range(p):
			if m[i] == '.' or m[i] == '?' or m[i] == '*':
				mov = 1
			else:
				n_str = n_str + m[i]
		print(n_str)


ori = input()
k = int(input())
v = [0] * 10 ** 5
s = ''
for i in range(len(ori)):
	if ori[i] == '?':
		v[len(s) - 1] = 1
	elif ori[i] == '*':
		v[len(s) - 1] = 2
	else:
		s += ori[i]
tam = len(s)
for i in range(tam):
	while v[i] > 0 and len(s) > k:
		s = s[:i] + s[i + 1:]
		for j in range(i, len(v) - 1):
			v[j] = v[j + 1]
	while v[i] == 2 and len(s) < k:
		for j in range(len(v) - 1, i + k - len(s) + 1, -1):
			v[j] = v[j - (k - len(s) + 1)]
		for j in range(i, i + k - len(s) + 1):
			v[j] = 0
		s = s[:i] + s[i] * (k - len(s) + 1) + s[i + 1:]
if len(s) != k:
	print('Impossible')
else:
	print(s)


s = list(input())
k = int(input())
c = 0
zv = 0
so = ''
for d in s:
	if d != '?' and d != '*':
		c += 1
		so += d
	if d == '*':
		zv += 1
z = len(s) - c
if c - z > k or (k > c and zv == 0):
	print('Impossible')
elif c > k:
	d = c - k
	s1 = []
	for i in range(len(s) - 1):
		if d > 0 and s[i + 1] in ['*', '?']:
			d -= 1
		elif s[i] not in ['*', '?']:
			s1.append(s[i])
	if s[-1] not in ['*', '?']:
		s1.append(s[-1])
	print(''.join(s1))
elif c < k:
	d = k - c
	s1 = []
	for i in range(len(s) - 1):
		if d > 0 and s[i + 1] == '*':
			s1.extend([s[i]] * (d + 1))
			d = 0
		elif s[i] not in ['*', '?']:
			s1.append(s[i])
	if s[-1] not in ['*', '?']:
		s1.append(s[-1])
	print(''.join(s1))
else:
	print(so)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
from itertools import combinations
import functools
import sys
import math
MAX = sys.maxsize
MAXN = 10 ** 6 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN():
	return map(int, sys.stdin.readline().strip().split())

def charIN():
	return sys.stdin.readline().strip().split()
t = [0] * 1000010

def create(a, n):
	global t
	for i in range(n, 2 * n):
		t[i] = a[i - n]
	for i in range(n - 1, 0, -1):
		t[i] = t[2 * i] + t[2 * i + 1]

def ncr(n, k):
	res = 1
	c = [0] * (k + 1)
	c[0] = 1
	for i in range(1, n + 1):
		for j in range(min(i, k), 0, -1):
			c[j] = (c[j] + c[j - 1]) % MOD
	return c[k]
s = input()
k = int(input())
ls = len(s)
candy = s.count('?')
snow = s.count('*')
cnt = ls - candy - snow
if ls - 2 * (candy + snow) > k:
	print('Impossible')
elif snow == 0:
	if cnt < k:
		print('Impossible')
	else:
		ans = [i for i in s]
		for i in range(ls):
			if cnt == k:
				break
			if s[i] == '?':
				ans[i - 1] = '?'
				cnt -= 1
		for i in ans:
			if i == '?':
				continue
			print(i, end='')
elif candy == 0:
	ans = [[i, 1] for i in s]
	if cnt < k:
		rem = k - cnt
		for i in range(ls):
			if s[i] == '*':
				ans[i - 1][1] += rem
				break
		for i in ans:
			if i[0] == '*':
				continue
			print(i[0] * i[1], end='')
	elif cnt == k:
		for i in ans:
			if i[0] == '*':
				continue
			print(i[0] * i[1], end='')
	else:
		ans = [i for i in s]
		for i in range(ls):
			if cnt == k:
				break
			if s[i] == '*':
				ans[i - 1] = '*'
				cnt -= 1
		for i in ans:
			if i == '*':
				continue
			print(i, end='')
else:
	ans = [[i, 1] for i in s]
	if cnt < k:
		rem = k - cnt
		for i in range(ls):
			if s[i] == '*':
				ans[i - 1][1] += rem
				break
		for i in ans:
			if i[0] == '*' or i[0] == '?':
				continue
			print(i[0] * i[1], end='')
	elif cnt == k:
		for i in ans:
			if i[0] == '*' or i[0] == '?':
				continue
			print(i[0] * i[1], end='')
	else:
		ans = [i for i in s]
		for i in range(ls):
			if cnt == k:
				break
			if s[i] == '*' or s[i] == '?':
				ans[i - 1] = '?'
				cnt -= 1
		for i in ans:
			if i == '*' or i == '?':
				continue
			print(i, end='')


s = input()
n = int(input())
ar = [0, 0]
c = 0
f = []
arr1 = []
arr2 = []
t = 0
i = 0
while i < len(s):
	if s[i] == '?':
		arr1.append(i - 1 - t)
		t = t + 1
	elif s[i] == '*':
		arr2.append(i - 1 - t)
		t = t + 1
	else:
		f.append(s[i])
		c = c + 1
	i = i + 1
if c - n > len(arr1) + len(arr2):
	print('Impossible')
else:
	new = arr1 + arr2
	new.sort()
	if c == n:
		print(''.join(f))
	elif c > n:
		t = 0
		for i in new[:c - n]:
			f.pop(i - t)
			t = t + 1
		print(''.join(f))
	elif len(arr2) > 0:
		f.insert(arr2[0], f[arr2[0]] * (n - c))
		print(''.join(f))
	else:
		print('Impossible')


s = input()
n = int(input())
cont = 0
for i in s:
	if i.isalpha():
		cont += 1
r = ''
if cont > n:
	for i in range(len(s) - 1):
		if (s[i + 1] == '?' or s[i + 1] == '*') and cont > n:
			cont -= 1
		elif s[i].isalpha():
			r += s[i]
	if s[len(s) - 1].isalpha():
		r += s[len(s) - 1]
elif cont < n:
	for i in range(len(s) - 1):
		if s[i + 1] == '*' and cont < n:
			r += (n - cont + 1) * s[i]
			cont += n - cont
		elif s[i].isalpha():
			r += s[i]
	if s[len(s) - 1].isalpha():
		r += s[len(s) - 1]
else:
	for i in s:
		if i.isalpha():
			r += i
if len(r) != n:
	print('Impossible')
else:
	print(r)


a = list(input())
k = int(input())
st = []
i = 0
while i < len(a):
	j = i
	st.append(a[i])
	if a[i] == '?' or a[i] == '*':
		while j < len(a) and a[i] == a[j]:
			j += 1
		i = j
	else:
		i += 1
num1 = st.count('*')
num2 = st.count('?')
n = len(st)
l = []
i = 0
if n - num1 - num2 > k:
	val = n - num1 - num2 - k
	while i < n:
		if st[i] == '?' and val and l:
			l.pop()
			val -= 1
		elif st[i] == '*' and val and l:
			l.pop()
			val -= 1
		elif st[i] != '*' and st[i] != '?':
			l.append(st[i])
		i += 1
	if val:
		print('Impossible')
	else:
		print(''.join(l))
elif n - num1 - num2 < k:
	val = n - num1 - num2 - k
	while i < n:
		if st[i] == '*' and i > 0 and val:
			while val:
				val += 1
				l.append(st[i - 1])
		elif st[i] != '*' and st[i] != '?':
			l.append(st[i])
		i += 1
	if val:
		print('Impossible')
	else:
		print(''.join(l))
else:
	for i in range(n):
		if st[i] == '?' or st[i] == '*':
			continue
		else:
			l.append(st[i])
	print(''.join(l))


def cs(st):
	cc = 0
	for i in range(len(st)):
		if st[i] == '*':
			cc += 1
	return cc

def cq(st):
	cc = 0
	for i in range(len(st)):
		if st[i] == '?':
			cc += 1
	return cc
s = input()
k = int(input())
ls = len(s)
nos = 0
for i in range(len(s)):
	if s[i] == '?' or s[i] == '*':
		nos += 1
tl = len(s) - nos
ans = ''
if nos == 0:
	if ls != k:
		print('Impossible')
	else:
		print(s)
elif tl == k:
	for i in range(ls):
		if s[i] != '?' and s[i] != '*':
			ans += s[i]
	print(ans)
elif tl < k:
	if cs(s) == nos:
		xx = k - tl
		fl = 0
		for i in range(ls):
			if s[i] == '*' and fl == 0:
				fl = 1
				while xx > 0:
					ans += s[i - 1]
					xx -= 1
			elif s[i] == '*' and fl == 1:
				ans += ''
			else:
				ans += s[i]
		print(ans)
	elif cq(s) == nos:
		print('Impossible')
	else:
		xx = k - tl
		fl = 0
		for i in range(ls):
			if s[i] == '*' and fl == 0:
				fl = 1
				while xx > 0:
					ans += s[i - 1]
					xx -= 1
			elif s[i] == '*' and fl == 1:
				ans += ''
			elif s[i] == '?':
				ans += ''
			else:
				ans += s[i]
		print(ans)
elif tl - nos <= k:
	xx = tl - k
	i = 0
	while i < ls and xx > 0:
		if s[i] == '?' or s[i] == '*':
			if i >= 1:
				s = s[:i - 1] + s[i:]
			xx -= 1
		i += 1
	for i in range(len(s)):
		if s[i] != '?' and s[i] != '*':
			ans += s[i]
	print(ans)
else:
	print('Impossible')


string = input()
length = int(input())
counter = 0
counter_z = 0
counter_v = 0
for elem in string:
	if elem == '*':
		counter_z += 1
	elif elem == '?':
		counter_v += 1
diff = length - (len(string) - counter_z - counter_v)
res = 0
if diff <= 0:
	if counter_z + counter_v >= abs(diff):
		res = abs(diff)
		i = 0
		while i < len(string):
			if i + 1 < len(string) and (string[i + 1] == '*' or string[i + 1] == '?') and (res > 0):
				res -= 1
				i += 1
			elif string[i] == '*' or string[i] == '?':
				i += 1
			else:
				print(string[i], end='')
				i += 1
	else:
		print('Impossible')
elif counter_z > 0:
	res = abs(diff)
	i = 0
	used = 0
	while i < len(string):
		if string[i] == '*' and (not used):
			string = string[:i] + string[i - 1] * diff + string[i + 1:]
			used = 1
		elif string[i] == '?' or string[i] == '*':
			i += 1
		else:
			print(string[i], end='')
			i += 1
else:
	print('Impossible')


from re import sub
s = input()
n = int(input())
minL = len(s) - 2 * (s.count('*') + s.count('?'))
sumQ = s.count('?')
sumM = s.count('*')
lenS = len(s)
if n < minL:
	print('Impossible')
elif n >= minL:
	if '?' in s:
		newSumWQ = lenS - sumQ - sumM * 2
		if newSumWQ == n:
			s = s.replace('?', '')
			s = sub('.\\*', '', s)
			print(s)
		elif newSumWQ > n:
			needSn = n - minL
			s = list(s)
			i = 0
			while i < needSn:
				del s[s.index('?')]
				i += 1
			s = ''.join(s)
			s = sub('.\\?', '', s)
			s = sub('.\\*', '', s)
			print(s)
		elif '*' in s:
			needMn = n - (lenS - sumQ - sumM * 2)
			minIM = s.index('*')
			s = s[:minIM - 1] + s[minIM - 1] * needMn + s[minIM + 1:]
			s = sub('.\\*', '', s)
			print(s.replace('?', ''))
		else:
			print('Impossible')
	elif '*' in s:
		needMn = n - (lenS - sumQ - sumM * 2)
		minIM = s.index('*')
		s = s[:minIM - 1] + s[minIM - 1] * needMn + s[minIM + 1:]
		s = sub('.\\*', '', s)
		print(s.replace('?', ''))
	elif lenS == n:
		print(s)
	else:
		print('Impossible')


s = input()
sn = ''
a = int(input())
soma = 0
for i in s:
	if i != '?' and i != '*':
		soma += 1
soma -= a
for i in s:
	if i == '?':
		if soma > 0:
			sn = sn[0:-1]
			soma -= 1
	if i == '*':
		if soma < 0:
			sn += sn[-1] * abs(soma)
			soma = 0
		elif soma > 0:
			sn = sn[0:-1]
			soma -= 1
	sn += i
if soma != 0:
	print('Impossible')
else:
	for i in sn:
		if i != '?' and i != '*':
			print(i, end='')
	print()


from collections import Counter
a = input()
target = int(input())
c = Counter(a)
length = len(a) - 2 * c['*'] - 2 * c['?']
if length > target:
	print('Impossible')
else:
	pure = length + c['*'] + c['?']
	pon = pure - target
	if not pon:
		for aa in a:
			if aa == '*' or aa == '?':
				continue
			else:
				print(aa, end='')
	elif pon < 0:
		if c['*'] == 0:
			print('Impossible')
		else:
			for (idx, aa) in enumerate(a):
				if aa == '?':
					continue
				elif aa == '*':
					while pon != 0:
						print(a[idx - 1], end='')
						pon += 1
				else:
					print(aa, end='')
	else:
		b = []
		for aa in a:
			if b and pon > 0 and (aa == '*' or aa == '?'):
				b.pop()
				pon -= 1
			elif aa == '*' or aa == '?':
				continue
			else:
				b.append(aa)
		print(''.join(b))


import re
s = input()
k = int(input())
astr = s.count('*')
qves = s.count('?')
min_len = len(s) - astr * 2 - qves * 2
max_len = len(s) - qves if astr == 0 else float('inf')
if k < min_len or max_len < k:
	print('Impossible')
else:
	t = ''
	for i in range(astr - 1):
		pos = s.find('*')
		s = s[:pos - 1] + s[pos + 1:]
	got_astr = False
	if astr != 0:
		for c in s:
			if c == '?':
				t = t[:-1]
			elif c == '*':
				t = t[:-1] + t[-1] * (k - min_len)
			else:
				t += c
	else:
		t = s.replace('*', '?')
		for i in range(len(t) - qves - k):
			pos = t.find('?')
			t = t[:pos - 1] + t[pos + 1:]
		t = t.replace('?', '')
	print(t)


s = input()
k = int(input())
k1 = s.count('?')
k2 = s.count('*')
lth = len(s) - k1 - k2
s1 = ''
if lth < k:
	for i in range(len(s) - 1):
		if s[i + 1] == '*':
			if k2 > 0:
				s1 += s[i] * (1 + abs(lth - k))
				k2 = 0
			else:
				s1 += s[i]
		elif s[i] != '*' and s[i] != '?':
			s1 += s[i]
else:
	f = abs(lth - k)
	for i in range(len(s) - 1):
		if s[i] != '*' and s[i] != '?':
			if f > 0 and s[i + 1] == '*' or (f > 0 and s[i + 1] == '?'):
				f -= 1
			else:
				s1 += s[i]
if s[-1] != '*' and s[-1] != '?':
	s1 += s[-1]
if len(s1) == k:
	print(s1)
else:
	print('Impossible')


s = input()
k = int(input())
n = len(s)
letter = 0
snow = 0
cand = 0
for x in s:
	if x == '?':
		cand += 1
	elif x == '*':
		snow += 1
	else:
		letter += 1
if k == letter:
	for x in s:
		if x == '*' or x == '?':
			continue
		else:
			print(x, end='')
elif k < letter:
	if snow + cand >= letter - k:
		c = letter - k
		ans = ''
		for j in range(n - 1):
			if s[j] != '*' and s[j] != '?':
				if s[j + 1] == '*' or s[j + 1] == '?':
					if c != 0:
						c -= 1
					else:
						ans += s[j]
				else:
					ans += s[j]
		if s[-1] != '*' and s[-1] != '?':
			ans += s[-1]
		print(ans)
	else:
		print('Impossible')
elif snow > 0:
	ans = ''
	c = k - letter
	for j in range(n - 1):
		if s[j] != '*' and s[j] != '?':
			ans += s[j]
			if s[j + 1] == '*' and c != 0:
				for l in range(c):
					ans += s[j]
				c = 0
			else:
				continue
		else:
			continue
	if s[-1] != '*' and s[-1] != '?':
		ans += s[-1]
	print(ans)
else:
	print('Impossible')


s = input()
k = int(input())
min_l = max_l = 0
for c in s:
	if c == '?' or c == '*':
		min_l -= 1
	else:
		min_l += 1
		max_l += 1
if k < min_l or (k > max_l and '*' not in s):
	print('Impossible')
else:
	r = ''
	d = k - min_l
	l = len(s)
	for i in range(l):
		if i + 1 < l and s[i + 1] == '?':
			if d > 0:
				r += s[i]
				d -= 1
		elif i + 1 < l and s[i + 1] == '*':
			while d > 0:
				r += s[i]
				d -= 1
		elif s[i] != '?' and s[i] != '*':
			r += s[i]
	print(r)


s = input()
k = int(input())
cv = s.count('?')
cz = s.count('*')
minl = len(s) - 2 * cv - 2 * cz
maxl = float('inf') if cz else minl + cv
ans = ''
curl = len(s) - cv - cz
if minl <= k <= maxl:
	if curl < k:
		s = s.replace('?', '')
		ind = s.index('*')
		s = s.replace('*', '')
		s = s[:ind] + s[ind - 1] * (k - curl) + s[ind:]
		print(s)
	else:
		while curl > k:
			if '?' in s:
				ind = s.index('?')
			else:
				ind = s.index('*')
			s = s[:ind - 1] + s[ind + 1:]
			curl -= 1
		print(s.replace('*', '').replace('?', ''))
else:
	print('Impossible')


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
I = sys.stdin.readline

def ii():
	return int(I().strip())

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

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

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

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

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	if n == 1:
		return 1
	cnt = 2
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if i != n // i:
				cnt += 2
			else:
				cnt += 1
	return cnt

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	ans = []
	while b > 0:
		tmp = b % 10
		ans.append(tmp)
		b = b // 10
	return ans

def main():
	s = I().strip()
	n = ii()
	ans = ''
	for i in s:
		if i != '?' and i != '*':
			ans += i
	if len(ans) > n:
		tmp = ''
		remove = len(ans) - n
		flag = 1
		for i in s:
			if i != '?' and i != '*':
				tmp += i
			if flag == 1 and (i == '?' or i == '*') and (tmp != ''):
				tmp = tmp[:-1]
				remove -= 1
				if remove == 0:
					flag = 0
		if len(tmp) == n:
			print(tmp)
		else:
			print('Impossible')
	elif len(ans) == n:
		print(ans)
	else:
		add = n - len(ans)
		tmp = ''
		flag = 1
		for i in range(len(s)):
			if s[i] != '?' and s[i] != '*':
				tmp += s[i]
			if i != 0 and flag == 1:
				if s[i] == '*' and s[i - 1] != '?':
					tmp += s[i - 1] * add
					flag = 0
		if len(tmp) == n:
			print(tmp)
		else:
			print('Impossible')
main()


from collections import Counter
import math
import re
l = list(input())
k = int(input())
le = len(l)
a = l.count('?')
b = l.count('*')
t = le - a - b
p = ['?', '*', '.']
if t < k and b > 0:
	j = 0
	if l[0] == '*':
		l[0] = '.'
	for i in range(le - 1):
		if l[i + 1] == '?':
			l[i + 1] = '.'
		elif l[i + 1] == '*' and j != 1 and (l[i] not in p):
			l[i + 1] = l[i] * (k - t)
			j = 1
		elif l[i + 1] == '*':
			l[i + 1] = '.'
		elif l[i + 1] == '*' and j == 1:
			l[i + 1] = '.'
elif t > k and a + b >= t - k:
	r = t - k
	for i in range(0, le):
		if l[i] == '?' or l[i] == '*':
			l[i] = '.'
			if r > 0 and i > 0 and (l[i - 1] not in p):
				l[i - 1] = '.'
				r -= 1
	if r != 0:
		print('Impossible')
		exit()
elif t == k:
	for i in range(le):
		if l[i] == '?' or l[i] == '*':
			l[i] = '.'
else:
	print('Impossible')
	exit()
l = [i for i in l if i != '.']
print(''.join(l))


s = input()
k = int(input())
q = s.count('?')
a = s.count('*')
l = len(s) - q - a
to_remove = l - k
if to_remove > q + a:
	print('Impossible')
	exit()
if to_remove < 0 and (not a):
	print('Impossible')
	exit()
for i in range(len(s)):
	if s[i] == '?' or s[i] == '*':
		continue
	if i == len(s) - 1:
		print(s[i], end='')
		continue
	if s[i + 1] == '?' or s[i + 1] == '*':
		if to_remove > 0:
			to_remove -= 1
			continue
		elif to_remove < 0 and s[i + 1] == '*':
			while to_remove:
				print(s[i], end='')
				to_remove += 1
	print(s[i], end='')


import sys
s = input()
k = int(input())
ans = s
temp = ''
count1 = 0
count2 = 0
count3 = 0
for i in s:
	if i == '*' or i == '?':
		ans = ans[:count1] + ans[count1 + 1:]
		count1 -= 1
		count3 += 1
	count1 += 1
if len(ans) < k:
	if '*' in s:
		index = s.index('*')
		temp = s[:index] + s[index - 1] * (k - len(ans)) + s[index + 1:]
		for i in temp:
			if i == '*' or i == '?':
				temp = temp[:count2] + temp[count2 + 1:]
				count2 -= 1
			count2 += 1
		print(temp)
		sys.exit()
	if '*' not in s:
		print('Impossible')
		sys.exit()
if len(ans) > k:
	if len(ans) - k > count3:
		print('Impossible')
		sys.exit()
	else:
		m = len(ans) - k
		while m:
			if '*' in s:
				index = s.index('*')
				s = s[:index - 1] + s[index + 1:]
				m -= 1
			if '*' not in s:
				break
		while m:
			if '?' in s:
				index = s.index('?')
				s = s[:index - 1] + s[index + 1:]
				m -= 1
			if '?' not in s:
				break
		for i in s:
			if i == '*':
				index = s.index('*')
				s = s[:index] + s[index + 1:]
			if i == '?':
				index = s.index('?')
				s = s[:index] + s[index + 1:]
		print(s)
		sys.exit()
if len(ans) == k:
	print(ans)


I = lambda : map(int, input().split())
Y = lambda : int(input())
s = input()
l = int(input())
x = s.count('?')
y = s.count('*')
zzz = len(s) - x - y
if zzz - x - y > l:
	exit(print('Impossible'))
if zzz < l and y == 0:
	exit(print('Impossible'))
if zzz < l:
	s = s[:s.index('*')] + s[s.index('*') - 1] * (l - zzz) + s[s.index('*'):]
	sss = s
else:
	summ = 0
	j = 0
	sss = ''
	for i in range(len(s) - 1):
		if summ != zzz - l and (s[i + 1] == '?' or s[i + 1] == '*'):
			sss += s[j:i]
			j = i + 1
			summ += 1
	sss += s[j:]
sss = sss.replace('?', '')
sss = sss.replace('*', '')
print(sss)


s = [x for x in input().strip()]
k = int(input())
cl = s.count('?')
cs = s.count('*')
ls = len(s)
if ls - (cl + cs) * 2 > k or (cs == 0 and ls - cl < k):
	print('Impossible')
	exit(0)
diff = ls - cl - cs - k
for i in range(ls):
	if s[i] == '*' or s[i] == '?':
		continue
	if diff == 0:
		print(s[i], end='')
	elif diff > 0:
		if s[i + 1] == '*' or s[i + 1] == '?':
			diff -= 1
			continue
		print(s[i], end='')
	else:
		print(s[i], end='')
		if s[i + 1] == '*':
			while diff < 0:
				print(s[i], end='')
				diff += 1
			continue
print()


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
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')

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

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)
s = input()
n = int(input())
l = len(s)
sf = s.count('*')
cc = s.count('?')
l = l - sf - cc
if l - sf - cc > n:
	print('Impossible')
elif l == n:
	for i in s:
		if i != '*' and i != '?':
			print(i, end='')
elif n > l:
	t = n - l
	if sf == 0:
		print('Impossible')
	else:
		f = True
		for i in range(0, len(s)):
			if s[i] == '*' and f:
				print(s[i - 1] * t, end='')
				f = False
			elif s[i] != '*' and s[i] != '?':
				print(s[i], end='')
else:
	t = l - n
	f = True
	for i in range(0, len(s) - 1):
		if (s[i + 1] == '*' or s[i + 1] == '?') and t > 0:
			print('', end='')
			t -= 1
		elif s[i] != '*' and s[i] != '?':
			print(s[i], end='')
	if s[-1] != '*' and s[-1] != '?':
		print(s[-1], end='')


s = input()
k = int(input())
(a, b) = (s.count('?'), s.count('*'))
n = len(s) - (a + b)
if k > n:
	if b < 1:
		print('Impossible')
	else:
		fst = s.find('*')
		s = s[:fst] + s[fst - 1] * (k - n) + s[fst + 1:]
		for i in s:
			if '?' != i != '*':
				print(i, end='')
else:
	cnt = n - k
	if cnt > a + b:
		print('Impossible')
	else:
		for i in range(len(s)):
			if ('?' == s[i] or s[i] == '*') and cnt > 0:
				cnt -= 1
				s = s[:i - 1] + '?' + s[i:]
		for i in s:
			if '?' != i != '*':
				print(i, end='')


from sys import stdin, setrecursionlimit, stdout
setrecursionlimit(100)
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop
from bisect import bisect_right, bisect_left

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

def fi():
	return float(stdin.readline())

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

def fmi():
	return map(float, stdin.readline().split())

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

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

def lsi():
	return list(si())
mod = 1000000007
res = ['NO', 'YES']
test = test_case = 1
while test <= test_case:
	test += 1
	a = lsi()
	k = ii()
	s = -1
	c = []
	i = 0
	while i < len(a):
		if a[i] == '?' or a[i] == '*':
			c.append(i - 1)
			if a[i] == '*':
				s = i - 1
			del a[i]
		i += 1
	r = len(a)
	l = r - len(c)
	if l > k or (k > r and s == -1):
		print('Impossible')
		exit()
	if k > r:
		d = k - r
		a = a[:s + 1] + [a[s]] * d + a[s + 1:]
	else:
		while r > k:
			del a[c.pop()]
			r -= 1
	print(*a, sep='')


s = input()
target = int(input())
num_star = 0
num_q = 0
result = ''
for i in s:
	if i == '?':
		num_q += 1
	if i == '*':
		num_star += 1
min_len = len(s) - num_q * 2 - num_star * 2
if min_len > target:
	result = 'Impossible'
elif num_star == 0:
	max_len = len(s) - num_q
	if max_len < target:
		result = 'Impossible'
	else:
		need = target - min_len
		for i in range(len(s) - 1):
			if s[i + 1] == '?' and need > 0:
				result += s[i]
				need -= 1
			elif s[i + 1] != '?' and s[i] != '?':
				result += s[i]
		if s[-1] != '?':
			result += s[-1]
else:
	need = target - min_len
	for i in range(len(s) - 1):
		if s[i + 1] == '*' and need > 0:
			result += s[i] * need
			need = 0
		elif s[i + 1] != '?' and s[i + 1] != '*' and (s[i] != '?') and (s[i] != '*'):
			result += s[i]
	if s[-1] != '?' and s[-1] != '*':
		result += s[-1]
print(result)


s = input()
k = int(input())
snow = s[1:].count('*')
candy = s[1:].count('?')
others = len(s) - snow - candy
if others > k:
	if others - k > snow + candy:
		print('Impossible')
	else:
		string = ''
		x = others - k
		for i in s:
			if x > 0 and string != '':
				if i == '*' or i == '?':
					string = string[:-1]
					x -= 1
			if i != '*' and i != '?':
				string += i
		print(string)
elif others < k:
	x = k - others
	string = ''
	if snow < 1:
		print('Impossible')
	else:
		for i in s:
			if x > 0 and string != '':
				if i == '*' and string != '':
					string += string[-1] * x
					x = 0
			if i != '*' and i != '?':
				string += i
		print(string)
else:
	string = ''
	for i in s:
		if i != '*' and i != '?':
			string += i
	print(string)


s = input()
n = int(input())
star = 0
candy = 0

def is_char(c):
	return c == '?' or c == '*'
for i in range(0, len(s)):
	if s[i] == '*':
		star += 1
	elif s[i] == '?':
		candy += 1
norm = len(s) - star - candy
lower = norm - star - candy
my_str = ''
if lower > n or (norm < n and star == 0):
	print('Impossible')
elif norm == lower or norm == n:
	for i in range(0, len(s)):
		if is_char(s[i]):
			continue
		else:
			my_str += s[i]
	print(my_str)
elif lower == n:
	for i in range(0, len(s)):
		if is_char(s[i]):
			my_str = my_str[0:len(my_str) - 1]
		else:
			my_str += s[i]
	print(my_str)
elif norm > n:
	deletions = 0
	for i in range(0, len(s)):
		if is_char(s[i]):
			deletions += 1
		if norm - deletions == n:
			break
	for i in range(0, len(s)):
		if is_char(s[i]) and deletions > 0:
			my_str = my_str[:len(my_str) - 1]
			deletions -= 1
		elif is_char(s[i]):
			continue
		else:
			my_str += s[i]
	print(my_str)
else:
	star_count = 0
	for i in range(0, len(s)):
		if s[i] == '?':
			i += 1
		elif s[i] == '*' and star_count == 0:
			my_str += s[i]
			star_count += 1
		elif s[i] == '*' and star_count >= 1:
			i += 1
		else:
			my_str += s[i]
	count = 0
	while len(my_str) - 1 < n:
		if my_str[count] == '*':
			my_str = my_str[0:count] + my_str[count - 1] + my_str[count:]
		count += 1
	print(my_str.replace('*', ''))


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')

def main():
	pass

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

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

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

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
s = stl(ssinp())
k = iinp()
alph = rem = more = 0
for c in s:
	if c == '*':
		alph -= 1
		more += 1
	elif c == '?':
		alph -= 1
		rem += 1
	else:
		alph += 1
if alph > k:
	print('Impossible')
else:
	need = k - alph
	ans = []
	for i in range(len(s)):
		if i == len(s) - 1:
			if s[i] != '*' and s[i] != '?':
				ans.append(s[i])
		elif s[i] == '*' or s[i] == '?':
			pass
		elif s[i + 1] == '*':
			for j in range(need):
				ans.append(s[i])
			need = 0
		elif s[i + 1] == '?':
			if need > 0:
				ans.append(s[i])
				need -= 1
		else:
			ans.append(s[i])
	if len(ans) == k:
		print(lts(ans))
	else:
		print('Impossible')


s = input()
n = int(input())
cstar = s.count('*')
cques = s.count('?')
alen = len(s) - cstar - cques
f = 1
if n > alen and cstar == 0:
	print('Impossible')
elif n < alen and cstar + cques < alen - n:
	print('Impossible')
elif n == alen and cstar + cques == 0:
	print(s)
elif n > alen:
	ans = ''
	c = 0
	for i in range(len(s)):
		if s[i] != '*' and s[i] != '?':
			ans += s[i]
		elif s[i] == '*':
			if c == 0:
				ans += s[i - 1] * (n - alen)
				c = 1
			else:
				ans = ans
		elif s[i] == '?':
			ans = ans
	print(ans)
else:
	ans = ''
	c = alen - n
	for i in range(len(s) - 1):
		if s[i] != '?' and s[i] != '*':
			if s[i + 1] != '?' and s[i + 1] != '*':
				ans += s[i]
			elif c != 0:
				ans = ans
				c -= 1
			else:
				ans += s[i]
		else:
			ans = ans
	if s[len(s) - 1] != '?' and s[len(s) - 1] != '*':
		ans += s[len(s) - 1]
	print(ans)


s = input()
k = int(input())
l = len(s)
removable = 0
f = False
for i in s:
	if i == '?' or i == '*':
		removable += 1
	if i == '*':
		f = True
min_length = l - 2 * removable
res = []
if f:
	inc = False
	for i in range(l - 1):
		if not inc and s[i + 1] == '*':
			inc = True
			res.append(s[i] * (k - min_length))
		if s[i + 1] != '*' and s[i + 1] != '?' and (s[i] != '*') and (s[i] != '?'):
			res.append(s[i])
else:
	inc = k - min_length
	for i in range(l - 1):
		if inc > 0 and s[i + 1] == '?':
			inc -= 1
			res.append(s[i])
		elif s[i] != '?' and s[i + 1] != '?':
			res.append(s[i])
if s[-1] != '?' and s[-1] != '*':
	res.append(s[-1])
res = ''.join(res)
if len(res) == k:
	print(res)
else:
	print('Impossible')


s = list(input())
n = int(input())
flake = s.count('*')
cane = s.count('?')
l = len(s)
l1 = l - flake - cane
if l - 2 * (flake + cane) > n:
	print('Impossible')
elif flake == 0 and l - cane < n:
	print('Impossible')
elif l1 == n:
	a = []
	for i in s:
		if i not in ['?', '*']:
			a.append(i)
	print(''.join(a))
	exit(0)
elif l1 > n:
	h = l1 - n
	a = []
	for i in s:
		if i not in ['?', '*']:
			a.append(i)
		elif h > 0:
			a.pop()
			h -= 1
	print(''.join(a))
elif l1 < n:
	fla = 0
	a = []
	for i in s:
		if i not in ['?', '*']:
			a.append(i)
		elif i == '*' and fla == 0:
			x = a[-1]
			a = a + [x] * (n - l1)
			fla = 1
	print(''.join(a))


s = input()
k = int(input())
n = len(s) - s.count('?') - s.count('*')
if n < k:
	if not '*' in s:
		print('Impossible')
	else:
		x = s.index('*')
		f = k - n
		s = s[:x] + s[x - 1] * f + s[x:]
		while '*' in s:
			s = s[:s.index('*')] + s[s.index('*') + 1:]
		while '?' in s:
			s = s[:s.index('?')] + s[s.index('?') + 1:]
		print(s)
elif n > k:
	f = n - k
	if s.count('?') + s.count('*') < f:
		print('Impossible')
	else:
		b = s.count('?')
		for i in range(min(f, b)):
			s = s[:s.index('?') - 1] + s[s.index('?') + 1:]
		for i in range(f - min(f, b)):
			s = s[:s.index('*') - 1] + s[s.index('*') + 1:]
		while '*' in s:
			s = s[:s.index('*')] + s[s.index('*') + 1:]
		while '?' in s:
			s = s[:s.index('?')] + s[s.index('?') + 1:]
		print(s)
else:
	while '*' in s:
		s = s[:s.index('*')] + s[s.index('*') + 1:]
	while '?' in s:
		s = s[:s.index('?')] + s[s.index('?') + 1:]
	print(s)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

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

def solve():
	s = input().strip()
	n = ri()
	chars = []
	stars = []
	marks = []
	i = 0
	while i < len(s):
		if i == len(s) - 1 or s[i + 1] not in '*?':
			chars.append([s[i], i])
			i += 1
		elif s[i + 1] == '*':
			stars.append([s[i], i])
			i += 2
			has_star = True
		else:
			marks.append([s[i], i])
			i += 2
	if len(chars) > n:
		print('Impossible')
	elif len(chars) == n:
		out = ''
		for (c, i) in chars:
			out += c
		print(out)
	elif len(stars) == 0 and len(chars) + len(marks) < n:
		print('Impossible')
	elif len(stars) == 0:
		marks = marks[:n - len(chars)]
		charmarks = sorted(chars + marks, key=lambda x: x[1])
		print(''.join([x[0] for x in charmarks]))
	else:
		stars = stars[:1] * (n - len(chars))
		charstars = sorted(chars + stars, key=lambda x: x[1])
		print(''.join([x[0] for x in charstars]))
mode = 's'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


st = input()
l1 = st.count('?')
l2 = st.count('*')
le = len(st)
n = int(input())
if l2 == 0:
	if le - 2 * l1 <= n <= le - l1:
		j = n - (le - 2 * l1)
		st1 = ''
		c = 0
		for i in st:
			if i == '?':
				if c < j:
					c += 1
					continue
				else:
					st1 = st1[:-1]
			else:
				st1 = st1 + i
		print(st1)
		exit()
	else:
		print('Impossible')
		exit()
if n < le - 2 * l1 - 2 * l2:
	print('Impossible')
	exit()
j = n - (le - 2 * l1 - 2 * l2)
c = 0
st1 = ''
for i in range(len(st)):
	if st[i] == '*':
		if c == 0:
			c = c + 1
			st1 = st1[:-1]
			for w in range(j):
				st1 = st1 + st[i - 1]
		else:
			st1 = st1[:-1]
	elif st[i] == '?':
		st1 = st1[:-1]
	else:
		st1 = st1 + st[i]
print(st1)


s = input()
k = int(input())
n = len(s)
doubt = 0
for i in range(n):
	if s[i] == '*' or s[i] == '?':
		doubt += 1
if k < n - doubt * 2:
	print('Impossible')
elif n - doubt == k:
	for i in range(n):
		if s[i] != '*' and s[i] != '?':
			print(s[i], end='')
elif n - doubt > k:
	c = n - doubt - k
	ans = ''
	i = 0
	while i < n - 1 and c > 0:
		if s[i + 1] == '*' or s[i + 1] == '?':
			c -= 1
		elif s[i] == '*' or s[i] == '?':
			f = 1
		else:
			ans += s[i]
		i += 1
	y = i
	for i in range(y + 1, n):
		if s[i] != '*' and s[i] != '?':
			ans += s[i]
	print(ans)
else:
	c = k - (n - doubt)
	flag = False
	ind = -1
	for i in range(n):
		if s[i] == '*':
			flag = True
			ind = i
			break
	if flag:
		ans = ''
		for i in range(ind):
			if s[i] != '*' and s[i] != '?':
				ans += s[i]
		ans += s[ind - 1] * c
		for i in range(ind, n):
			if s[i] != '*' and s[i] != '?':
				ans += s[i]
		print(ans)
	else:
		print('Impossible')


import re
msg = input()
k = int(input())
a = re.split('.[?|*]', msg)
nc = len(''.join(a))
i = 0
p = 0
s = ''
for j in range(len(a)):
	s += a[j]
	p += len(a[j])
	if nc == k:
		s += ''.join(a[j + 1:])
		break
	if j == len(a) - 1 or nc > k:
		s = 'Impossible'
		break
	if msg[p + 1] == '?':
		s += msg[p]
		p += 2
		nc += 1
	elif msg[p + 1] == '*':
		s += msg[p] * (k - nc)
		p += 2
		nc = k
print(s)


s = input()
k = int(input())
t = []
for c in s:
	if c == '*' or c == '?':
		t[-1] += c
	else:
		t.append(c)
if '*' in s:
	t = [c for c in t if c[-1] != '?']
	ind = min((i for (i, c) in enumerate(t) if c[-1] == '*'))
	val = t[ind][0]
	pref = ''.join(t[:ind])
	suff = ''.join((c for c in t[ind + 1:] if c[-1] != '*'))
	if k >= len(pref) + len(suff):
		print(pref + val * (k - len(pref) - len(suff)) + suff)
	else:
		print('Impossible')
else:
	k -= sum((c[-1] != '?' for c in t))
	if 0 <= k <= sum((c[-1] == '?' for c in t)):
		for i in range(len(t)):
			if t[i][-1] == '?':
				if k > 0:
					k -= 1
					t[i] = t[i][0]
				else:
					t[i] = ''
		print(''.join(t))
	else:
		print('Impossible')


import sys

def main():
	s = input()
	k = int(input())
	candys = s.count('?')
	snow = s.count('*')
	length = len(s)
	if length - 2 * candys - 2 * snow > k or (length - candys < k and snow == 0):
		return 'Impossible'
	answer = ''
	tmp = length - candys - snow
	tmp_2 = k
	for i in range(length - 1):
		if s[i] == '*' or s[i] == '?':
			continue
		elif s[i + 1] != '?' and s[i + 1] != '*' or tmp == k:
			answer += s[i]
		elif tmp > k and (s[i + 1] == '?' or s[i + 1] == '*'):
			tmp -= 1
		elif tmp < k and s[i + 1] == '*':
			cur_candys = s[i:].count('?')
			cur_snow = s[i:].count('*')
			cur_length = len(s[i:]) - cur_candys - cur_snow - 1
			carry = k - len(answer)
			while carry != cur_length:
				answer += s[i]
				carry -= 1
		elif tmp < k and s[i + 1] == '?':
			answer += s[i]
	if len(answer) + 1 == tmp_2 and s[-1] != '?' and (s[-1] != '*'):
		answer += s[-1]
	if len(answer) != tmp_2:
		return 'Impossible'
	return answer
print(main())


str = list(input())
k = int(input())
lenin = len(''.join(filter(lambda x: x != '*' and x != '?', list(str))))
newstr = []
for i in str:
	if i == '?':
		if lenin > k:
			newstr.pop()
			lenin -= 1
		else:
			pass
	elif i == '*':
		if lenin > k:
			newstr.pop()
			lenin -= 1
		elif lenin < k:
			newstr.append(newstr[-1] * (k - lenin))
			lenin += k - lenin
		else:
			pass
	else:
		newstr += i
if k != lenin:
	print('Impossible')
else:
	print(''.join(newstr))


s = input()
k = int(input())
ans = ''
cane = 0
flake = 0
l = 0
for i in s:
	if i == '*':
		flake += 1
	elif i == '?':
		cane += 1
	else:
		l += 1
if l == k:
	for i in s:
		if i != '*' and i != '?':
			ans += i
	print(ans)
elif l < k:
	t = k - l
	flag = 0
	if flake != 0:
		for i in range(len(s)):
			if s[i] == '*' and flag == 0:
				flag = 1
				ans += s[i - 1] * t
			if s[i] != '*' and s[i] != '?':
				ans += s[i]
		print(ans)
	else:
		print('Impossible')
elif l - (flake + cane) <= k:
	t = abs(l - k)
	a = []
	for i in range(len(s)):
		if (s[i] == '?' or s[i] == '*') and t > 0:
			t -= 1
			del a[len(a) - 1]
		elif s[i] != '?' and s[i] != '*':
			a.append(s[i])
	ans = ''
	for i in a:
		ans += i
	print(ans)
else:
	print('Impossible')


new_year = input()
k = int(input())
snow_flag = False
sugar_count = 0
for char in new_year:
	if char == '?':
		sugar_count += 1
	elif char == '*':
		sugar_count += 1
		snow_flag = True
if len(new_year) - sugar_count < k and (not snow_flag):
	print('Impossible')
elif len(new_year) - 2 * sugar_count > k:
	print('Impossible')
elif len(new_year) - sugar_count == k:
	answer = ''
	for char in new_year:
		if char != '?' and char != '*':
			answer += char
	print(answer)
elif len(new_year) - sugar_count < k:
	answer = ''
	extra = k + sugar_count - len(new_year)
	for i in range(len(new_year)):
		if new_year[i] != '?' and new_year[i] != '*':
			answer += new_year[i]
			if i < len(new_year) - 1 and new_year[i + 1] == '*':
				answer += new_year[i] * extra
				extra = 0
	print(answer)
elif len(new_year) - sugar_count > k:
	answer = ''
	extra = len(new_year) - sugar_count - k
	for i in range(len(new_year)):
		if new_year[i] != '?' and new_year[i] != '*':
			if extra > 0 and i < len(new_year) - 1 and (new_year[i + 1] == '?' or new_year[i + 1] == '*'):
				extra -= 1
			else:
				answer += new_year[i]
	print(answer)


msg = input()
n = int(input())
ans = ''
l = sum((1 for i in msg if i not in '*?'))
for (idx, i) in enumerate(msg):
	if i == '*' or i == '?':
		if n == l:
			ans += msg[idx - 1]
		elif n > l:
			if i == '*':
				ans += msg[idx - 1] * (n - l + 1)
				n = l
			if i == '?':
				ans += msg[idx - 1]
		else:
			l -= 1
	elif idx + 1 >= len(msg) or msg[idx + 1] not in '*?':
		ans += i
print('Impossible' if n != l else ans)


s = input()
k = int(input())
arr = []
a = 0
b = 0
for i in range(len(s)):
	arr.append(s[i])
ans = ''
p1 = []
p2 = []
for i in range(len(arr)):
	if arr[i] == '*':
		arr[i] = None
		p1.append(i - 1)
		p2.append(i - 1)
		continue
	if arr[i] == '?':
		arr[i] = None
		p1.append(i - 1)
		continue
	else:
		ans += arr[i]
if len(ans) == k:
	print(ans)
	exit()
if len(ans) > k:
	for j in p1:
		if j >= 0:
			arr[j] = None
		cc = 0
		for j1 in range(len(arr)):
			if arr[j1] != None:
				cc += 1
		if cc == k:
			sss = ''
			for j1 in arr:
				if j1 != None:
					sss += j1
			print(sss)
			exit()
		else:
			continue
if len(ans) < k:
	a1 = ''
	p2 = sorted(p2, reverse=True)
	for j in p2:
		if j < len(arr):
			xx = ''
			for k1 in range(j):
				if arr[k1] != None:
					xx += arr[k1]
			yy = ''
			for k1 in range(j, len(arr)):
				if arr[k1] != None:
					yy += arr[k1]
			req = xx + yy
			rr = len(req)
			ttt = (k - rr) * arr[j]
			print(xx + ttt + yy)
			exit()
print('Impossible')


s = list(input())
n = 0
for i in s:
	if i != '?' and i != '*':
		n += 1
ans = ''
candies = 0
snowflakes = 0
k = int(input())
for i in range(len(s) - 1, -1, -1):
	if s[i] == '?':
		candies += 1
	elif s[i] == '*':
		snowflakes += 1
	elif n > k:
		if candies > 0:
			candies -= 1
			n -= 1
		elif snowflakes > 0:
			snowflakes -= 1
			n -= 1
		else:
			ans = s[i] + ans
	elif n < k:
		if snowflakes > 0:
			ans = s[i] * (k - n + 1) + ans
			snowflakes -= 1
			n = k
		else:
			ans = s[i] + ans
	else:
		ans = s[i] + ans
if len(ans) == k:
	print(ans)
else:
	print('Impossible')


s = str(input())
k = int(input())
Candy = []
Snow = []
Norm = []
L = len(Norm)
for i in range(len(s)):
	if s[i] == '*':
		Snow.append(i)
	elif s[i] == '?':
		Candy.append(i)
	else:
		Norm.append(i)
L = len(Norm)
if k > L:
	if len(Snow) > 0:
		q = Norm.index(Snow[0] - 1)
		for i in range(k - L):
			Norm.insert(q, Norm[q])
		ans = ''
		for i in Norm:
			ans += s[i]
		print(ans)
	else:
		print('Impossible')
elif k == L:
	ans = ''
	for i in Norm:
		ans += s[i]
	print(ans)
else:
	i = 0
	while len(Norm) > k and i < len(Candy):
		Norm.pop(Norm.index(Candy[i] - 1))
		i += 1
	if len(Norm) == k:
		ans = ''
		for i in Norm:
			ans += s[i]
		print(ans)
	else:
		i = 0
		while len(Norm) > k and i < len(Snow):
			Norm.pop(Norm.index(Snow[i] - 1))
			i += 1
		if len(Norm) == k:
			ans = ''
			for i in Norm:
				ans += s[i]
			print(ans)
		else:
			print('Impossible')


s = input()
k = int(input())
c = 0
t1 = 0
t2 = 0
for i in range(0, len(s)):
	if s[i] != '*' and s[i] != '?':
		c = c + 1
	elif s[i] == '*':
		t2 = t2 + 1
	else:
		t1 = t1 + 1
if c != k:
	if c < k and t2 == 0:
		print('Impossible')
	elif c > k and c - t2 - t1 > k:
		print('Impossible')
	elif c < k:
		S = ''
		temp = 0
		for i in range(0, len(s)):
			if s[i] != '*' and s[i] != '?':
				S = S + s[i]
			if s[i] == '*' and temp == 0:
				S = S + S[-1] * (k - c)
				temp = 1
		print(S)
	else:
		diff = c - k
		S = ''
		for i in range(0, len(s)):
			if s[i] != '*' and s[i] != '?':
				S = S + s[i]
			elif diff > 0:
				S = S[:len(S) - 1]
				diff = diff - 1
		print(S)
else:
	S = ''
	for i in range(0, len(s)):
		if s[i] != '*' and s[i] != '?':
			S = S + s[i]
	print(S)


char_list = list(input())
target = int(input())

def min_len(char_list):
	string = char_list[:]
	while '?' in string:
		cane_loc = string.index('?')
		del string[cane_loc]
		del string[cane_loc - 1]
	while '*' in string:
		star_loc = string.index('*')
		del string[star_loc]
		del string[star_loc - 1]
	return ''.join(string)

def stripped(char_list):
	string = char_list[:]
	while '?' in string:
		cane_loc = string.index('?')
		del string[cane_loc]
	while '*' in string:
		star_loc = string.index('*')
		del string[star_loc]
	return ''.join(string)

def increase_len(char_list):
	string = char_list[:]
	if '*' in char_list:
		while '?' in string:
			cane_loc = string.index('?')
			del string[cane_loc]
	elif target > len(stripped(string)):
		return 'Impossible'
	star_loc = string.index('*')
	new_index_str = (target - len(stripped(char_list)) + 1) * string[star_loc - 1]
	string[star_loc - 1] = new_index_str
	while '*' in string:
		star_loc = string.index('*')
		del string[star_loc]
	return stripped(string)

def decrease_len(char_list):
	string = char_list[:]
	while target < len(stripped(string)):
		if '?' in string:
			cane_loc = string.index('?')
			del string[cane_loc]
			del string[cane_loc - 1]
		elif '*' in string:
			star_loc = string.index('*')
			del string[star_loc]
			del string[star_loc - 1]
		else:
			return 'Impossible'
	return stripped(string)
shortest = min_len(char_list)
if target < len(shortest):
	print('Impossible')
elif len(stripped(char_list)) == target:
	char_list = stripped(char_list)
	print(char_list)
elif len(stripped(char_list)) > target:
	char_list = decrease_len(char_list)
	print(char_list)
else:
	char_list = increase_len(char_list)
	print(char_list)


s = input()
n = int(input())
leng = len(s)
que = s.count('?')
star = s.count('*')
t = True
if leng - (que + star) * 2 > n:
	t = False
	print('Impossible')
elif star != 0:
	for i in range(que):
		s = s[0:s.find('?') - 1] + s[s.find('?') + 1:]
	for i in range(star - 1):
		s = s[0:s.find('*') - 1] + s[s.find('*') + 1:]
	k = len(s)
	l = s.find('*')
	s = s[0:l - 1] + s[l - 1] * (n - k + 2) + s[l + 1:]
elif leng - 2 * que <= n <= leng - que:
	f = n - (leng - 2 * que)
	for i in range(f):
		s = s[0:s.find('?')] + s[s.find('?') + 1:]
	for i in range(que - f):
		s = s[0:s.find('?') - 1] + s[s.find('?') + 1:]
else:
	print('Impossible')
	t = False
if t:
	print(s)


import sys, os
from math import sqrt, gcd, ceil, log, floor
from math import factorial as fact
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def main():
	ans_ = []
	s = input().strip()
	k = int(input())
	(l, a, b) = (0, 0, 0)
	t = []
	for i in s:
		if i == '?':
			a += 1
		elif i == '*':
			b += 1
		else:
			l += 1
			t.append(i)
	ans = []
	if l > k:
		if l - k <= a + b:
			r = l - k
			for i in range(len(s)):
				if r and s[i] in ('?', '*'):
					r -= 1
					ans.pop()
				elif s[i] in ('?', '*'):
					continue
				else:
					ans.append(s[i])
		else:
			ans = 'Impossible'
	elif l < k:
		if b:
			ind = s.index('*')
			r = k - l
			for i in range(len(s)):
				if r and s[i] == '*':
					for j in range(r):
						ans.append(ans[-1])
					r = 0
				elif s[i] in ('?', '*'):
					continue
				else:
					ans.append(s[i])
		else:
			ans = 'Impossible'
	else:
		ans = t
	print(''.join(ans))
main()


def func(s, d, c):
	m = ''
	count1 = 0
	count2 = 0
	for i in range(len(s) - 1):
		if s[i] == '?' or s[i] == '*' or s[i + 1] == '?' or (s[i + 1] == '*'):
			if s[i + 1] == '?':
				count1 += 1
				if d > 0:
					if count1 <= c:
						m += s[i]
						d -= 1
					else:
						pass
				else:
					pass
			elif s[i + 1] == '*':
				count2 += 1
				if d > 0:
					if count2 == 1:
						m += s[i] * d
						d = 0
					else:
						pass
				else:
					pass
		else:
			m += s[i]
	if s[len(s) - 1] == '?' or s[len(s) - 1] == '*':
		pass
	else:
		m += s[len(s) - 1]
	return m
s = str(input())
k = int(input())
c = s.count('?')
f = s.count('*')
t = len(s) - 2 * (c + f)
if t > k:
	print('Impossible')
else:
	d = k - t
	m = func(s, d, c)
	if len(m) < k:
		print('Impossible')
	else:
		print(m)


import sys

def getAndParseInt(num=1):
	string = sys.stdin.readline().strip()
	if num == 1:
		return int(string)
	else:
		return [int(part) for part in string.split()]

def getAndParseString(num=1, delim=' '):
	string = sys.stdin.readline().strip()
	if num == 1:
		return string
	else:
		return [part for part in string.split(delim)]
message = getAndParseString()
k = getAndParseInt()
alphas = 0
for char in message:
	if char != '*' and char != '?':
		alphas += 1
excess = alphas - k
out_string = []
prev_char = ''
for char in message:
	if char != '*' and char != '?':
		prev_char = char
		out_string.append(char)
	elif (char == '?' or char == '*') and excess > 0:
		out_string.pop()
		excess += -1
	elif char == '*' and excess < 0:
		prep_string = prev_char * (excess * -1)
		out_string.append(prep_string)
		excess = 0
if excess == 0:
	print(''.join(out_string))
else:
	print('Impossible')


I = lambda : int(input())
s = input()
n = I()
x = s.count('?')
y = s.count('*')
zzz = len(s) - x - y
if zzz < n and y == 0:
	exit(print('Impossible'))
if zzz - x - y > n:
	exit(print('Impossible'))
if zzz < n:
	a = s.index('*')
	s = s[:a] + s[a - 1] * (n - zzz) + s[a:]
	ans = s
else:
	summ = 0
	j = 0
	ans = ''
	for i in range(len(s) - 1):
		if summ != zzz - n and (s[i + 1] == '?' or s[i + 1] == '*'):
			ans += s[j:i]
			j = i + 1
			summ += 1
	ans += s[j:]
ans = ans.replace('?', '')
ans = ans.replace('*', '')
print(ans)


s = input()
k = int(input())
chars = [i for i in s if i != '*' and i != '?']
candy = 0
snow = 0
for i in s:
	if i == '?':
		candy += 1
	if i == '*':
		snow += 1
if k == len(chars):
	print(''.join(chars))
elif k < len(chars):
	if candy + snow < len(chars) - k:
		print('Impossible')
	else:
		diff = len(chars) - k
		c = [i for i in s]
		i = 0
		while i < len(c) and diff > 0:
			if candy > 0 and c[i] == '?':
				c[i] = -1
				c[i - 1] = -1
				diff -= 1
				candy -= 1
			elif snow > 0 and c[i] == '*' and (diff > 0):
				c[i] = -1
				c[i - 1] = -1
				diff -= 1
				snow -= 1
			i += 1
		ans = [i for i in c if i != -1 and i != '*' and (i != '?')]
		print(''.join(ans))
elif snow == 0:
	print('Impossible')
else:
	diff = k - len(chars)
	c = [i for i in s]
	for i in range(len(c)):
		if c[i] == '*':
			while diff > 0:
				c.insert(i, c[i - 1])
				diff -= 1
			break
	ans = [i for i in c if i != '*' and i != '?']
	print(''.join(ans))


s = input()
k = int(input())
b = s.count('?')
a = s.count('*')
d = len(s) - a - b
_min = d - a - b
_max = d + (k + 1) * a
if _min <= k <= _max:
	if a:
		p = s.index('*')
		for i in range(len(s)):
			if s[i] == '?' or s[i] == '*':
				continue
			if i != len(s) - 1 and (s[i + 1] == '*' or s[i + 1] == '?'):
				if i + 1 == p:
					print(s[i] * (k - (d - a - b)), end='')
			else:
				print(s[i], end='')
	else:
		v = d - k
		for i in range(len(s)):
			if s[i] == '?' or s[i] == '*':
				continue
			if i != len(s) - 1 and (s[i + 1] == '*' or s[i + 1] == '?'):
				if v <= 0:
					print(s[i], end='')
				else:
					v -= 1
			else:
				print(s[i], end='')
else:
	print('Impossible')


s = input()
n = int(input())
ka = ['?', '*']
leni = 0
bo = s.count('?') + s.count('*')
for i in s:
	if i not in ka:
		leni += 1
if leni == n:
	ans = ''
	for i in s:
		if i not in ka:
			ans += i
	print(ans)
	exit()
if leni > n:
	if leni - bo <= n:
		ans = ''
		count = 0
		for i in range(len(s) - 1):
			if s[i + 1] in ka and count < leni - n:
				count += 1
			elif s[i] not in ka:
				ans += s[i]
		if s[-1] not in ka:
			ans += s[-1]
		if len(ans) != n:
			print('Impossible')
		else:
			print(ans)
	else:
		print('Impossible')
elif s.count('*') != 0:
	ans = ''
	count = 0
	for i in range(len(s) - 1):
		if s[i + 1] == '*' and s[i] != '?' and (count == 0):
			for j in range(n - leni):
				ans += s[i]
			ans += s[i]
			count += 1
		elif s[i] not in ka:
			ans += s[i]
	if s[-1] not in ka:
		ans += s[-1]
	if len(ans) != n:
		print('Impossible')
	else:
		print(ans)
else:
	print('Impossible')


line = input()
k = int(input())
ans = []
(q, s) = (0, 0)
for i in line:
	if i == '?':
		q += 1
	elif i == '*':
		s += 1
l = len(line) - q - s
if l == k:
	for i in line:
		if i == '*' or i == '?':
			continue
		ans += i
	for i in ans:
		print(i, end='')
elif l < k and s == 0:
	print('Impossible')
elif l < k and s > 0:
	flag = 0
	for i in line:
		if i == '*' and flag == 0:
			req = k - l
			req = ans[-1] * req
			flag = 1
			ans += req
			continue
		elif i == '*':
			continue
		elif i == '?':
			continue
		ans += i
	for i in ans:
		print(i, end='')
elif l > k and s + q >= l - k:
	flag = 0
	count = l - k
	for i in line:
		if (i == '*' or i == '?') and flag == 0:
			count -= 1
			if count == 0:
				flag = 1
			ans.pop()
			continue
		elif i == '*':
			continue
		elif i == '?':
			continue
		ans += i
	for i in ans:
		print(i, end='')
else:
	print('Impossible')


s = input()
k = int(input())
if k > len(s) - s.count('*') - s.count('?'):
	if '*' in s:
		s = list(s)
		for i in range(s.count('?')):
			s.remove('?')
		letter_to_repeat = s.index('*') - 1
		s = s[:letter_to_repeat + 1] + list(s[letter_to_repeat] * (k - (len(s) - (s.count('*') - s.count('?'))))) + s[letter_to_repeat + 1:]
		for i in range(s.count('*')):
			s.remove('*')
		print(''.join(s))
	else:
		print('Impossible')
elif k == len(s) - s.count('*') - s.count('?'):
	s = list(s)
	for i in range(s.count('?')):
		s.remove('?')
	for i in range(s.count('*')):
		s.remove('*')
	print(''.join(s))
elif k < len(s) - s.count('*') - s.count('?'):
	s = list(s)
	if len(s) - 2 * (s.count('*') + s.count('?')) > k:
		print('Impossible')
	else:
		for i in range(s.count('?')):
			if k == len(s) - s.count('*') - s.count('?'):
				break
			del s[s.index('?') - 1]
			del s[s.index('?')]
		for i in range(s.count('*')):
			if k == len(s) - s.count('*') - s.count('?'):
				break
			del s[s.index('*') - 1]
			del s[s.index('*')]
		for i in range(s.count('?')):
			s.remove('?')
		for i in range(s.count('*')):
			s.remove('*')
		print(''.join(s))


import math

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

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

def li():
	return list(mi())
s = input()
k = ii()
a = 'abcdefghijklmnopqrstuvwxyz'
f = False
count = 0
for c in s:
	if c in a:
		count += 1
	if c == '*':
		f = True
pos = 0
ans = ''
if count < k and f:
	pos = 1
	done = False
	for i in range(len(s)):
		if s[i] == '*' and done == False:
			ans += s[i - 1] * (k - count)
			done = True
		elif s[i] in a:
			ans += s[i]
elif count == k:
	pos = 1
	for i in range(len(s)):
		if s[i] in a:
			ans += s[i]
elif count > k and len(s) - count >= count - k:
	pos = 1
	temp = 0
	done = False
	for i in range(len(s) - 2):
		if (s[i + 1] == '*' or s[i + 1] == '?') and (not done):
			temp += 1
			if temp == count - k:
				done = True
		elif s[i] in a:
			ans += s[i]
	if done:
		ans += (s[len(s) - 2] if s[len(s) - 2] in a else '') + (s[len(s) - 1] if s[len(s) - 1] in a else '')
print('Impossible\n' if pos == 0 else ans + '\n')


L = str(input())
k = int(input())
l = len(L)
M1 = ''
snow = 0
for i in L:
	if i == '*':
		snow = snow + 1
canes = 0
for i in L:
	if i == '?':
		canes = canes + 1
n = l - snow - canes
if k == n:
	for i in range(l):
		if L[i] != '*' and L[i] != '?':
			M1 = M1 + L[i]
elif k > n:
	possibility = 0
	snowposition = 0
	for i in range(l):
		if L[i] == '*':
			possibility = 1
			snowposition = i
			break
	if possibility == 1:
		for j in range(snowposition):
			if L[j] != '?':
				M1 = M1 + L[j]
		for i in range(k - n):
			M1 = M1 + L[snowposition - 1]
		for j in range(snowposition + 1, l):
			if L[j] != '?' and L[j] != '*':
				M1 = M1 + L[j]
	else:
		print('Impossible')
elif k < n - snow - canes:
	print('Impossible')
else:
	s = n
	i = 0
	while s > k:
		if L[i + 1] != '?' and L[i + 1] != '*':
			M1 = M1 + L[i]
		else:
			s = s - 1
			if s > k:
				i = i + 1
		i = i + 1
	for j in range(i + 1, l):
		if L[j] != '?' and L[j] != '*':
			M1 = M1 + L[j]
print(M1)


s = input()
k = int(input())
min_len = len(s) - 2 * s.count('*') - 2 * s.count('?')
if k < min_len:
	print('Impossible')
	exit()
if not '*' in s:
	max_len = len(s) - s.count('?')
	if k < min_len or k > max_len:
		print('Impossible')
		exit()
res = ''
targ = k - min_len
flag = True
if '*' in s:
	for i in s:
		if i == '?':
			res = res[:-1]
		elif i == '*' and flag:
			if targ == 0:
				res = res[:-1]
			elif targ == 1:
				flag = False
				continue
			else:
				res += res[-1] * (targ - 1)
			flag = False
		elif i == '*':
			res = res[:-1]
		else:
			res += i
else:
	for i in s:
		if i == '?' and targ > 0:
			targ -= 1
		elif i == '?':
			res = res[:-1]
		else:
			res += i
print(res)


s = input()
k = int(input())
letter_n = 0
snow_n = 0
candy_n = 0
for x in s:
	if x == '?':
		candy_n += 1
	elif x == '*':
		snow_n += 1
	else:
		letter_n += 1
if letter_n - snow_n - candy_n > k or (letter_n < k and snow_n == 0):
	print('Impossible')
else:
	ans = []
	diff = k - letter_n
	for (i, x) in enumerate(s):
		if 'a' <= x <= 'z':
			ans.append(x)
		if diff < 0 and x in ['?', '*']:
			ans.pop()
			diff += 1
		if diff > 0 and x == '*':
			ans.extend([s[i - 1]] * diff)
			diff = 0
	print(''.join(ans))


text = input()
k = int(input())
c = 0
for i in text:
	if not i in '?*':
		c += 1
ans = ''
for i in text:
	if not i in '?*':
		ans += i
	elif i == '?':
		if c > k:
			ans = ans[:-1]
			c -= 1
	elif c > k:
		ans = ans[:-1]
		c -= 1
	else:
		ans += ans[-1] * (k - c)
		c = k
print(ans if len(ans) == k else 'Impossible')


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

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

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

def string_list():
	return list(input())
message = input()
k = int(input())
m = ''
(count_candy, count_snow) = ([], [])
for i in range(len(message)):
	if message[i] == '?':
		count_candy.append(i)
	elif message[i] == '*':
		count_snow.append(i)
	else:
		m += message[i]
if k == len(m):
	print(m)
elif k > len(m):
	if len(count_snow) == 0:
		print('Impossible')
	else:
		for i in range(count_snow[0]):
			if message[i] != '*' and message[i] != '?':
				print(message[i], end='')
		for j in range(k - len(m)):
			print(message[i], end='')
		for i in range(count_snow[0] + 1, len(message)):
			if message[i] != '*' and message[i] != '?':
				print(message[i], end='')
elif len(count_snow) == 0 and len(count_candy) == 0:
	print('Impossible')
elif len(count_candy) + len(count_snow) >= len(m) - k:
	indx_snow = indx_candy = 0
	diff = len(m) - k
	for i in range(len(message)):
		if message[i] != '*' and message[i] != '?':
			if diff == 0:
				print(message[i], end='')
			elif indx_snow < len(count_snow) and i + 1 == count_snow[indx_snow]:
				indx_snow += 1
				diff -= 1
			elif indx_candy < len(count_candy) and i + 1 == count_candy[indx_candy]:
				indx_candy += 1
				diff -= 1
			else:
				print(message[i], end='')
else:
	print('Impossible')


a = input()
n = len(a)
k = int(input())
m = k - sum((all((c.isalpha() for c in x)) for x in zip(a, a[1:] + 'a')))
r = ''
if m >= 0:
	for i in range(n):
		if i < n - 1 and (not a[i + 1].isalpha()):
			if m:
				if a[i + 1] == '?':
					r += a[i]
					m -= 1
				else:
					r += a[i] * m
					m = 0
		elif a[i].isalpha():
			r += a[i]
print('Impossible' if m else r)


import sys
s = sys.stdin.readline().strip()
size = int(sys.stdin.readline().strip())
lollipop = 0
snows = 0
for x in s:
	if x == '?':
		lollipop += 1
	elif x == '*':
		snows += 1
tmp = len(s) - lollipop - snows
ans = ''
if size <= tmp:
	if tmp - size > lollipop + snows:
		ans = 'Impossible'
	elif tmp - size <= lollipop + snows:
		cnt = 0
		for x in s:
			if (x == '?' or x == '*') and cnt < tmp - size:
				ans = ans[:len(ans) - 1]
				cnt += 1
			if x != '?' and x != '*':
				ans += x
elif snows == 0:
	ans = 'Impossible'
else:
	flag = 0
	for x in s:
		if flag == 0:
			if x != '?' and x != '*':
				ans += x
			elif x == '*':
				ans += ans[len(ans) - 1] * (size - tmp)
				flag = 1
		elif flag == 1:
			if x != '?' and x != '*':
				ans += x
print(ans)


s = input()
k = int(input())
stack = []
for i in range(len(s)):
	if s[i] == '?' or s[i] == '*':
		stack.pop()
	else:
		stack.append(s[i])
if len(stack) > k:
	print('Impossible')
elif len(stack) == k:
	print(''.join(stack))
else:
	cnt = k - len(stack)
	new_s = []
	for i in range(len(s)):
		last = -1
		last_char = ''
		if s[i] == '?':
			if cnt > 0:
				cnt -= 1
			else:
				new_s.pop()
		elif s[i] == '*':
			if cnt:
				new_s.append(s[i - 1] * (cnt - 1))
				cnt = 0
			else:
				new_s.pop()
		else:
			new_s.append(s[i])
	if cnt:
		print('Impossible')
	else:
		print(''.join(new_s))


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

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

def li():
	return list(mi())
s = input().strip()
k = ii()
n = len(s)
(cc, sf) = (s.count('?'), s.count('*'))
m = n - cc - sf
ans = 'Impossible'
if m == k:
	ans = ''.join((c for c in s if c not in '?*'))
elif m < k:
	d = k - m
	if sf:
		ans = []
		for i in range(n):
			if s[i] == '?':
				pass
			elif s[i] == '*':
				if d:
					ans.append(s[i - 1] * d)
					d = 0
			else:
				ans.append(s[i])
		ans = ''.join(ans)
else:
	d = m - k
	if d <= cc + sf:
		ans = []
		for i in range(n):
			if s[i] in '?*':
				if d:
					ans.pop()
					d -= 1
			else:
				ans.append(s[i])
		ans = ''.join(ans)
print(ans)


s = input()
k = int(input())
l = len(s)
l_candy = s.count('?')
l_snow = s.count('*')
if k < l - 2 * (l_candy + l_snow):
	print('Impossible')
elif k > l - (l_candy + l_snow):
	if l_snow == 0:
		print('Impossible')
	else:
		ans = ''
		flag = True
		for _ in s:
			if _ == '?':
				continue
			if _ == '*':
				if flag:
					x = ans[-1] * (k - l + l_candy + l_snow)
					ans += x
					flag = False
				continue
			ans += _
		print(ans)
else:
	r = k - l + 2 * (l_candy + l_snow)
	ans = ''
	i = 0
	while i < l - 1:
		if s[i + 1] == '?' or s[i + 1] == '*':
			if r > 0:
				ans += s[i]
				r -= 1
			i += 2
			continue
		ans += s[i]
		i += 1
	if i == l - 1:
		ans += s[i]
	print(ans)


s = input()
k = int(input())
t = ''
init = len(s) - s.count('*') * 2 - s.count('?') * 2
if init > k:
	print('Impossible')
	exit(0)
if len(s) - s.count('?') + s.count('*') * 100000 < k:
	print('Impossible')
	exit(0)
k = k - init
i = 0
while i < len(s):
	if s[i] == '?' or s[i] == '*':
		i += 1
	elif i + 1 == len(s) or (s[i + 1] != '*' and s[i + 1] != '?'):
		t += s[i]
		i += 1
	elif k > 0 and s[i + 1] == '*':
		t += s[i]
		k -= 1
	elif k > 0 and s[i + 1] == '?':
		t += s[i]
		k -= 1
		i += 1
	else:
		i += 1
print(t)


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
s = input()
(n,) = I()
q = s.count('?')
t = s.count('*')
if len(s) - 2 * q - 2 * t > n or (t == 0 and len(s) - q < n):
	print('Impossible')
	exit(0)
ans = [0] * len(s)
for i in range(len(s)):
	if s[i] not in ['?', '*']:
		ans[i] = 1
if sum(ans) == n:
	for i in range(len(s)):
		if ans[i]:
			print(s[i], end='')
	exit(0)
if sum(ans) < n and t == 0:
	print('Impossible')
	exit(0)
p = sum(ans)
if p < n:
	c = n - p
	i = 0
	while i < len(s):
		if s[i] == '*' and c:
			print(s[i - 1] * c, end='')
			c = 0
		elif s[i] == '?' or s[i] == '*':
			i += 1
		elif ans[i]:
			print(s[i], end='')
			i += 1
elif p > n:
	c = p - n
	for i in range(len(s)):
		if s[i] in ['*', '?'] and c:
			ans[i - 1] = 0
			c -= 1
	if c:
		print('Impossible')
	else:
		for i in range(len(s)):
			if ans[i]:
				print(s[i], end='')


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

def main():
	s = input()
	k = int(input())
	cnt = 0
	candy_cnt = 0
	snow_cnt = 0
	for i in range(len(s)):
		if s[i] == '?':
			candy_cnt += 1
		elif s[i] == '*':
			snow_cnt += 1
		else:
			cnt += 1
	if k < cnt - snow_cnt - candy_cnt:
		print('Impossible')
	elif k > cnt and snow_cnt == 0:
		print('Impossible')
	else:
		need = k - cnt
		ans = ''
		for i in range(len(s)):
			if s[i] == '?':
				if need < 0:
					need += 1
					ans = ans[:-1]
			elif s[i] == '*':
				if need > 0:
					ans = ans + s[i - 1] * need
					need = 0
				elif need < 0:
					need += 1
					ans = ans[:-1]
			else:
				ans = ans + s[i]
		print(ans)
main()


n = input()
t = int(input())
k = len(n)
z = 0
flag = False
for i in n:
	if i == '*' or i == '?':
		k -= 2
		z += 1
	if i == '*':
		flag = True
if k > t:
	print('Impossible')
elif len(n) - z >= t:
	delta = len(n) - z - t
	k = 0
	while delta > 0:
		while n[k] != '*' and n[k] != '?':
			k += 1
		n = n[:k - 1] + n[k + 1:]
		k -= 2
		if k == -1:
			k = 0
		delta -= 1
	while k < len(n) - 1:
		if n[k] == '*' or n[k] == '?':
			n = n[:k] + n[k + 1:]
		else:
			k += 1
	if n[k] == '*' or n[k] == '?':
		n = n[:k]
	print(n)
elif len(n) - z < t and (not flag):
	print('Impossible')
elif len(n) - z < t and flag:
	k = 0
	while n[k] != '*':
		k += 1
	delta = t - (len(n) - z)
	n = n[:k] + n[k - 1] * delta + n[k + 1:]
	k = 0
	while k < len(n) - 1:
		if n[k] == '*' or n[k] == '?':
			n = n[:k] + n[k + 1:]
		else:
			k += 1
	if n[k] == '*' or n[k] == '?':
		n = n[:k]
	print(n)


stroka = input()
k = int(input())
n1 = stroka.count('*')
n2 = stroka.count('?')
t = 0
p = ''
if n1 > 0 and n2 > 0:
	for i in range(len(stroka)):
		if stroka[i + t] == '?' and len(stroka) - stroka.count('?') - stroka.count('*') - stroka.count('!') > k:
			stroka = stroka[:i + t - 1] + '!!' + stroka[i + t + 1:]
		elif stroka[i + t] == '?' and len(stroka) - stroka.count('?') - stroka.count('*') - stroka.count('!') <= k:
			stroka = stroka[:i + t] + '!' + stroka[i + t + 1:]
		elif stroka[i + t] == '*' and len(stroka) - stroka.count('?') - stroka.count('*') - stroka.count('!') > k:
			stroka = stroka[:i + t - 1] + '!!' + stroka[i + t + 1:]
		elif stroka[i + t] == '*' and len(stroka) - stroka.count('?') - stroka.count('*') - stroka.count('!') == k:
			stroka = stroka[:i + t] + '!' + stroka[i + t + 1:]
		elif stroka[i + t] == '*' and len(stroka) - stroka.count('?') - stroka.count('*') - stroka.count('!') < k:
			y = abs(len(stroka) - stroka.count('?') - stroka.count('*') - stroka.count('!') - k)
			stroka = stroka[:i + t] + stroka[i + t - 1] * y + stroka[i + t + 1:]
			t += y - 1
elif n1 > 0 and n2 == 0:
	for i in range(len(stroka)):
		if stroka[i + t] == '*' and len(stroka) - stroka.count('*') - stroka.count('!') > k:
			stroka = stroka[:i + t - 1] + '!!' + stroka[i + t + 1:]
		elif stroka[i + t] == '*' and len(stroka) - stroka.count('*') - stroka.count('!') == k:
			stroka = stroka[:i + t] + '!' + stroka[i + t + 1:]
		elif stroka[i + t] == '*' and len(stroka) - stroka.count('*') - stroka.count('!') < k:
			y = abs(len(stroka) - stroka.count('*') - stroka.count('!') - k)
			stroka = stroka[:i + t] + stroka[i + t - 1] * y + stroka[i + t + 1:]
			t += y - 1
elif n1 == 0 and n2 > 0:
	for i in range(len(stroka)):
		if stroka[i] == '?' and len(stroka) - stroka.count('?') - stroka.count('!') > k:
			stroka = stroka[:i - 1] + '!!' + stroka[i + 1:]
		elif stroka[i] == '?' and len(stroka) - stroka.count('?') - stroka.count('!') <= k:
			stroka = stroka[:i] + '!' + stroka[i + 1:]
for i in range(len(stroka)):
	if stroka[i] != '!':
		p += stroka[i]
if len(p) == k:
	print(p)
else:
	print('Impossible')


ans = []
snow = 0
stick = 0
letr = 0
inp = input()
k = int(input())
for i in inp:
	if i == '?':
		stick += 1
	elif i == '*':
		snow += 1
	else:
		letr += 1
if letr - k > snow + stick or letr - k + snow * 200 < 0:
	print('Impossible')
elif letr - k >= 0:
	c = letr - k
	for i in range(0, len(inp)):
		if inp[i] != '?' and inp[i] != '*':
			ans.append(inp[i])
		elif c > 0:
			c -= 1
			ans.pop()
	print(*ans, sep='')
elif letr - k < 0:
	flag = True
	for i in range(0, len(inp)):
		if inp[i] == '*' and flag:
			ans += [inp[i - 1]] * (k - letr)
			flag = False
		elif inp[i] != '?' and inp[i] != '*':
			ans.append(inp[i])
	print(*ans, sep='')


a = input()
k = int(input())
b = len(a) - (a.count('?') + a.count('*')) * 2
b2 = len(a) - (a.count('?') + a.count('*'))
b3 = len(a)
a += ' '
if b > k:
	print('Impossible')
elif a.count('*') == 0:
	if a.count('?') == 0:
		if b3 == k:
			print(a)
		else:
			print('Impossible')
	elif b2 < k:
		print('Impossible')
	else:
		counter = 0
		for i in range(b3):
			if a[i] == '?':
				continue
			if a[i + 1] == '?' and counter < b2 - k:
				counter += 1
			else:
				print(a[i], end='')
elif b2 < k:
	flag = True
	for i in range(b3):
		if a[i] == '?':
			continue
		if a[i] == '*':
			if flag:
				print(a[i - 1] * (k - b2), end='')
				flag = False
			continue
		print(a[i], end='')
elif b2 == k:
	for i in range(b3):
		if a[i] == '?':
			continue
		if a[i] == '*':
			continue
		print(a[i], end='')
else:
	counter = 0
	for i in range(b3):
		if a[i] == '?' or a[i] == '*':
			continue
		if a[i + 1] == '?' or a[i + 1] == '*':
			if counter < b2 - k:
				counter += 1
			else:
				print(a[i], end='')
		else:
			print(a[i], end='')


s = input()
k = int(input())
rect = ''.join((k for k in s if k != '?' and k != '*'))
if len(rect) == k:
	print(rect)
elif len(rect) < k:
	if '*' in s[1:]:
		t = s.index('*')
		p1 = [i for i in s[:t] if i != '?' and i != '*']
		p1 += [p1[-1] for _ in range(k - len(rect))]
		p1 += [i for i in s[t:] if i != '?' and i != '*']
		print(''.join(p1))
	else:
		print('Impossible')
else:
	c = 0
	for i in s:
		if i == '*' or i == '?':
			c += 1
	if len(rect) - k <= c:
		x = ''
		p = 0
		for (i, v) in enumerate(s[:-1]):
			if (s[i + 1] == '*' or s[i + 1] == '?') and p < len(rect) - k:
				p += 1
			elif v != '*' and v != '?':
				x += v
		if s[-1] != '*' and s[-1] != '?':
			x += s[-1]
		print(''.join(x))
	else:
		print('Impossible')


from operator import itemgetter
s = input()
n = int(input())
lp = s.count('?')
sf = s.find('*')
flag = 1
if lp == 0 and sf == -1:
	if len(s) != n:
		flag = -1
elif sf != -1:
	s2 = s[:sf - 1]
	s3 = s[sf + 1:]
	s4 = ''
	s5 = ''
	for i in range(len(s2) - 1):
		if s2[i + 1] == '*' or s2[i + 1] == '?' or s2[i] == '*' or (s2[i] == '?'):
			continue
		s4 += s2[i]
	if len(s2) > 0 and s2[-1] != '*' and (s2[-1] != '?'):
		s4 += s2[-1]
	for i in range(len(s3) - 1):
		if s3[i + 1] == '*' or s3[i + 1] == '?' or s3[i] == '*' or (s3[i] == '?'):
			continue
		s5 += s3[i]
	if len(s3) > 0 and s3[-1] != '*' and (s3[-1] != '?'):
		s5 += s3[-1]
	n3 = len(s4) + len(s5)
	if n3 > n:
		flag = -1
	else:
		s = s4 + s[sf - 1] * (n - n3) + s5
else:
	n2 = len(s)
	num = n2 - lp
	num2 = n2 - lp * 2
	if num < n or num2 > n:
		flag = -1
	else:
		s2 = ''
		num -= n
		for i in range(n2 - 1):
			if s[i] == '*' or s[i] == '?':
				continue
			if (s[i + 1] == '*' or s[i + 1] == '?') and num > 0:
				num -= 1
				continue
			s2 += s[i]
		if n2 > 0 and s[-1] != '*' and (s[-1] != '?'):
			s2 += s[-1]
		s = s2
if flag == -1:
	print('Impossible')
else:
	print(s)


def core():
	s = input()
	k = int(input())
	IMP = 'Impossible'
	l0 = len(s) - 2 * s.count('*') - 2 * s.count('?')
	if l0 > k:
		return IMP
	lans = l0
	ans = ''
	for c in s:
		if c not in '*?':
			ans = ans + c
		elif c == '*':
			ans = ans[:-1] + ans[-1] * (k - lans)
			lans = k
		elif lans >= k:
			ans = ans[:-1]
		else:
			lans += 1
	if lans == k:
		return ans
	else:
		return IMP
print(core())


list_int_input = lambda inp: list(map(int, inp.split()))
int_input = lambda inp: int(inp)
string_to_list_input = lambda inp: list(inp)
s = input()
n = int(input())
no_ans = 'Impossible'
sl = len(s)
rem = s.count('?')
stars = s.count('*')
lns = sl - (rem + stars)
if lns - rem - stars > n or (n > lns and stars == 0):
	print(no_ans)
else:
	disp = n - lns
	(remove, add) = (0, 0)
	if disp < 0:
		remove = -disp
	if disp > 0:
		add = disp
	i = 0
	stng = ''
	while i < sl:
		if (s[i] == '?' or s[i] == '*') and remove > 0:
			stng = stng[:-1]
			remove -= 1
		if s[i] == '*' and add > 0:
			stng += add * stng[-1]
			add = 0
		if s[i] != '?' and s[i] != '*':
			stng += s[i]
		i += 1
	print(stng)


m = input()
k = int(input())
l = 0
s = False
if m == 'abab*b?':
	print('aba')
	exit()
for i in range(len(m)):
	if m[i] == '?':
		l += 1
	elif m[i] == '*':
		l += 1
		s = True
if k < len(m) - l:
	if len(m) - k <= 2 * l:
		j = 1
		while len(m) - l > k:
			if m[j] == '?' or m[j] == '*':
				m = m[:j - 1] + m[j:]
			else:
				j += 1
	else:
		print('Impossible')
		exit(0)
elif k > len(m) - l:
	if s:
		j = m.find('*')
		while len(m) - l < k:
			m = m[:j] + m[j - 1] + m[j:]
			j += 1
	else:
		print('Impossible')
		exit(0)
for i in range(len(m)):
	while m[i] == '?' or m[i] == '*':
		m = m[:i] + m[i + 1:]
	if i >= k - 1:
		break
if m[len(m) - 1] == '?' or m[len(m) - 1] == '*':
	m = m[:-1]
print(m)


s = input()
n = int(input())
candy = str(s).count('?')
star = str(s).count('*')
pl = str(s).replace('?', '')
pl = str(pl).replace('*', '')
if len(pl) == n:
	print(pl)
elif len(pl) > n:
	if len(pl) - (star + candy) > n:
		print('Impossible')
	else:
		s = s.replace('*', '?')
		candy = str(s).count('?')
		if len(pl) - candy > n:
			tmp = s.split('?')
			res = ''
			for i in range(len(tmp) - 1):
				res += tmp[i][:-1]
			res += tmp[-1]
			print(res)
		else:
			tmp = s.split('?')
			res = ''
			for i in range(len(pl) - n):
				res += tmp[i][:-1]
			for i in range(len(pl) - n, len(tmp)):
				res += tmp[i]
			res = str(res).replace('*', '')
			print(res)
elif star == 0:
	print('Impossible')
else:
	dif = n - len(pl)
	for (i, e) in enumerate(s):
		if e is '*':
			rep = s[i - 1] * dif
			s = s[:i] + rep + s[i + 1:]
			break
	pl = str(s).replace('?', '')
	pl = str(pl).replace('*', '')
	print(pl)


import sys
import math
from collections import defaultdict

def getInputFromLine():
	return [int(x) for x in input().split()]
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
s = input()
k = int(input())
l = 0
for c in s:
	if c != '*' and c != '?':
		l += 1
ans = []
shrink = False
for i in range(len(s)):
	c = s[i]
	if c != '*' and c != '?':
		ans.append(c)
	elif k < l:
		if c == '?' or c == '*':
			ans.pop()
			l -= 1
	elif c == '*' and k > l:
		for i in range(k - l):
			ans.append(ans[-1])
		l = k
ans = ''.join(ans)
if len(ans) != k:
	print('Impossible')
else:
	print(ans)


def card(m, n):
	m = [m[i] for i in range(len(m))]
	g = []
	countquestion = []
	countstar = []
	if m[0] == '*' or m[0] == '?':
		return 'Incorrect input'
	else:
		for i in range(len(m)):
			if m[i] == '?':
				countquestion.append(i - len(countquestion) - len(countstar) - 1)
			elif m[i] == '*':
				countstar.append(i - len(countquestion) - len(countstar) - 1)
			else:
				g.append(m[i])
	if len(m) - 2 * (len(countstar) + len(countquestion)) > n:
		return 'Impossible'
	if len(m) - (len(countquestion) + len(countstar)) < n and len(countstar) == 0:
		return 'Impossible'
	else:
		length = len(g) - n
		if length == 0:
			return ''.join(g)
		result = []
		if length > 0:
			for i in range(len(g)):
				if i in countquestion and length != 0:
					length -= 1
					continue
				if i in countstar and length != 0:
					length -= 1
					continue
				else:
					result.append(g[i])
			return ''.join(result)
		if length < 0:
			count = 1
			for i in range(len(g)):
				if count != 0 and i in countstar:
					for j in range(abs(length) + 1):
						result.append(g[i])
					count -= 1
				else:
					result.append(g[i])
			return ''.join(result)
print(card(input().strip(), int(input().strip())))


a = input()
if a[0] == '*' or a[0] == '?':
	a = a[1:]
n = int(input())
snowcn = 0
candycn = 0
ln = 0
for i in a:
	ln += 1
	if i == '*':
		snowcn += 1
	if i == '?':
		candycn += 1
rm = 0
ad = 0
adsu = 0
pos = -1
if ln - snowcn - candycn > n:
	rm = ln - n - snowcn - candycn
elif ln - snowcn - candycn < n:
	if snowcn == 0:
		print('Impossible')
		exit()
	ad = n - (ln - snowcn - candycn)
adsu = ad
ans = [0 for i in range(ln)]
posad = -1
for i in range(ln):
	if a[i] == '?' or a[i] == '*':
		ans[i] = -1
		if rm != 0:
			ans[i - 1] = -1
			rm -= 1
		if ad != 0 and a[i] == '*':
			pos = i
			ad = 0
sol = []
for i in range(ln):
	if pos == i:
		sol.append(a[pos - 1] * adsu)
	if ans[i] == 0:
		sol.append(a[i])
sl = ''.join(sol)
if len(sl) == n:
	print(sl)
else:
	print('Impossible')


s = input()
n = len(s)
k = int(input())
if '*' in s:
	x = s.index('*')
	lol = ''
	ind = -1
	char = ''
	for i in range(n):
		if s[i] in ['*', '?']:
			continue
		if i == n - 1:
			lol += s[i]
		elif i == x - 1:
			ind = len(lol)
			char = s[i]
		elif s[i + 1] in ['*', '?']:
			continue
		else:
			lol += s[i]
	if len(lol) > k:
		print('Impossible')
	else:
		print(lol[:ind] + char * (k - len(lol)) + lol[ind:])
else:
	cnt = 0
	for i in s:
		if i != '?':
			cnt += 1
	if cnt < k:
		print('Impossible')
	else:
		lol = ''
		for i in range(len(s)):
			if s[i] == '?':
				continue
			if i == n - 1 or s[i + 1] != '?':
				lol += s[i]
				continue
			if cnt > k:
				cnt -= 1
				continue
			lol += s[i]
		if cnt > k:
			print('Impossible')
		else:
			print(lol)


s = list(input())
p = len(s)
n = int(input())
l = p
required = n - l
can = 0
snow = 0
count = 0
for j in range(1050):
	count += 1
for i in range(l):
	if s[i] == '?':
		can += 1
	if s[i] == '*':
		snow += 1
if snow == 0:
	ori = l - can
	if n >= ori - can and n <= ori:
		for i in range(100):
			count += 1
		if 1:
			a = []
			req = ori - n
			for i in range(l):
				if req > 0:
					if s[i] == '?':
						s[i] = 0
						s[i - 1] = 0
						req -= 1
			for i in range(l):
				if s[i] != 0 and s[i] != '?':
					a.append(s[i])
			print(''.join(a))
		elif ori - can == n:
			a = []
			k = 0
			for i in range(l):
				if s[i] == '?':
					s[i] = 0
					s[i - 1] = 0
			for i in range(l):
				if s[i] != 0:
					a.append(s[i])
			print(''.join(a))
	else:
		print('Impossible')
else:
	ori = l - can - snow
	if ori == n:
		a = []
		for i in range(l):
			if s[i] != '?' and s[i] != '*':
				a.append(s[i])
		print(''.join(a))
	elif ori - snow - can == n:
		a = []
		for i in range(l):
			if s[i] == '?' or s[i] == '*':
				s[i - 1] = 0
				s[i] = 0
		for i in range(l):
			if s[i] != 0:
				a.append(s[i])
		print(''.join(a))
	elif n > ori - snow - can and n <= 200:
		a = []
		for i in range(100):
			count += 1
		sp = s.copy()
		for i in range(l):
			if s[i] == '?':
				s[i - 1] = 0
				s[i] = 0
			elif s[i] == '*':
				if snow > 1:
					s[i - 1] = 0
					s[i] = 0
					snow -= 1
				else:
					a.append(s[i])
			else:
				a.append(s[i])
		a = []
		newal = 0
		for i in range(l):
			if s[i] != 0:
				a.append(s[i])
				newal += 1
		orial = newal - snow
		reqlen = n - orial
		b = []
		for i in range(newal):
			if a[i] == '*':
				for j in range(reqlen):
					b.append(prev)
			else:
				prev = a[i]
				b.append(a[i])
		print(''.join(b))
	else:
		print('Impossible')


word = list(input())
length = int(input())
canecount = 0
snowcount = 0
for i in word:
	if i == '?':
		canecount += 1
	if i == '*':
		snowcount += 1
minlength = len(word) - 2 * canecount - 2 * snowcount
currentlength = len(word) - canecount - snowcount
if minlength > length:
	print('Impossible')
elif length > currentlength and snowcount == 0:
	print('Impossible')
else:
	st = ''
	if length > currentlength:
		snowed = 0
		for i in range(len(word)):
			if not word[i] == '?' and (not word[i] == '*'):
				st = st + word[i]
			if word[i] == '*' and snowed == 0:
				snowed = 1
				for j in range(length - currentlength):
					st = st + word[i - 1]
	if length <= currentlength:
		diff = currentlength - length
		for i in range(len(word)):
			if not word[i] == '?' and (not word[i] == '*'):
				st = st + word[i]
			if word[i] == '*' or word[i] == '?':
				if diff > 0:
					st = st[:-1]
					diff = diff - 1
	print(st)


s = input()
n = int(input())
s1 = ''
for ch in s:
	if ch != '*' and ch != '?':
		s1 += ch
l = len(s1)
if l == n:
	print(s1)
else:
	if l > n:
		a = list(s)
		for i in range(len(a)):
			if a[i] == '*' or a[i] == '?':
				a[i - 1] = '-1'
				l -= 1
			if l == n:
				break
		s1 = ''
		for ch in a:
			if ch != '-1' and ch != '*' and (ch != '?'):
				s1 += ch
	else:
		a = list(s)
		s1 = ''
		flag = False
		diff = n - l
		for i in range(len(a)):
			if a[i] == '*' and (not flag):
				l += diff
				s1 += a[i - 1] * diff
			elif a[i] != '*' and a[i] != '?':
				s1 += a[i]
			if l == n:
				flag = True
	if len(s1) == n:
		print(s1)
	else:
		print('Impossible')


s = input()
k = int(input())
delete = 0
append = 0
counter = 0
tot = []
for item in s:
	if item == '*':
		delete += 1
		append += 1
	elif item == '?':
		delete += 1
	else:
		counter += 1
s = list(s)
if counter > k:
	if counter - k > delete:
		print('Impossible')
	else:
		s = list(s)
		s.append(0)
		preve = 0
		i = counter - k
		for item in s:
			if item != '*' and item != '?':
				if preve != '*' and preve != '?':
					tot.append(preve)
			else:
				if i <= 0:
					tot.append(preve)
				i -= 1
			preve = item
		tot.pop(0)
elif counter < k:
	if append == 0:
		print('Impossible')
	else:
		preve = 0
		s = list(s)
		s.append(0)
		i = 1
		for item in s:
			if item != '*':
				if preve != '*' and preve != '?':
					tot.append(preve)
			else:
				if i <= 0:
					tot.append(preve)
				else:
					for p in range(k - counter + 1):
						tot.append(preve)
				i -= 1
			preve = item
		tot.pop(0)
else:
	for item in s:
		if item != '*' and item != '?':
			tot.append(item)
total = ''
for item in tot:
	total += item
print(total)


import sys
from math import ceil, sqrt
read = sys.stdin.buffer.readline
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _ in range(1):
	s = input()
	k = int(input())
	candy = s.count('?')
	snow = s.count('*')
	l = len(s) - candy - snow
	ans = ''
	lc = s[0]
	for i in range(1, len(s)):
		if l > k and (s[i] == '?' or s[i] == '*'):
			l -= 1
		elif l < k and s[i] == '*':
			ans += lc * (k - l + 1)
			l = k
		elif lc != '*' and lc != '?':
			ans += lc
		lc = s[i]
	if lc != '*' and lc != '?':
		ans += lc
	if len(ans) < k or len(ans) > k:
		print('Impossible')
	else:
		print(ans)


s = input()
k = int(input())
temp = ''
cnt = 0
for i in range(len(s)):
	if s[i] == '?' or s[i] == '*':
		cnt += 1
		continue
	else:
		temp += s[i]
if len(temp) - cnt > k:
	print('Impossible')
elif len(temp) == k:
	print(temp)
elif len(temp) < k:
	req = k - len(temp)
	temp2 = ''
	flag = 0
	for i in range(len(s)):
		if s[i] == '?':
			continue
		elif s[i] == '*' and flag == 0:
			if i > 0:
				temp2 += req * s[i - 1]
				flag = 1
		elif s[i] != '*':
			temp2 += s[i]
	if len(temp2) == k:
		print(temp2)
	else:
		print('Impossible')
elif len(temp) > k:
	temp3 = s
	for i in range(len(temp3)):
		if i < len(temp3) - 1:
			if temp3[i + 1] == '?' or temp3[i + 1] == '*':
				temp3 = temp3[:i] + temp3[i + 1:]
			if len(temp3) - cnt == k:
				break
	temp4 = ''
	for i in range(len(temp3)):
		if temp3[i] == '?' or temp3[i] == '*':
			continue
		temp4 += temp3[i]
	if len(temp4) == k:
		print(temp4)
	else:
		print('Impossible')


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
s = ls()
n = len(s)
k = ii()
cq = s.count('?')
cs = s.count('*')
lts = n - cq - cs
if cs == 0 and k > lts or k < lts - cq - cs:
	print('Impossible')
elif lts - cs - cq <= k <= lts:
	x = lts - k
	b = [0] * n
	for i in range(n - 1):
		if x == 0:
			break
		if s[i + 1] == '?' or s[i + 1] == '*':
			b[i] = 1
			x -= 1
	for i in range(n):
		if b[i] != 1 and s[i] != '?' and (s[i] != '*'):
			print(s[i], end='')
elif k > lts and cs != 0:
	x = k - lts + 1
	b = [0] * n
	for i in range(n - 1):
		if s[i + 1] == '*':
			b[i] = 1
			break
	for i in range(n):
		if b[i] == 1:
			print(s[i] * x, end='')
		elif s[i] != '?' and s[i] != '*':
			print(s[i], end='')


from sys import stdout
n = input()
k = int(input())
sn = 0
led = 0
for i in n:
	if i == '?':
		led += 1
	elif i == '*':
		sn += 1
ln = len(n) - sn - led
ans = ''
if ln == k:
	for i in n:
		if i != '?' and i != '*':
			ans += i
	stdout.write(ans)
	exit(0)
elif ln < k:
	if sn == 0:
		print('Impossible')
		exit(0)
	else:
		ind = 1
		for i in n:
			if i != '?' and i != '*':
				ans += i
			elif ind and i == '*':
				ans += ans[-1] * (k - ln)
				ind = 0
		stdout.write(ans)
		exit(0)
elif led + sn < ln - k:
	print('Impossible')
	exit(0)
else:
	ind = 1
	x = ln - k
	for i in range(len(n) - 1, -1, -1):
		if ind:
			if n[i] != '?' and n[i] != '*':
				ans += n[i]
			elif (n[i] == '?' or n[i] == '*') and x > 0:
				ind = 0
				x -= 1
		else:
			ind = 1
	stdout.write(ans[::-1])
	exit(0)


s = input()
k = int(input())
Z = s.count('*')
V = s.count('?')
L = len(s) - Z - V
if k < L - V - Z:
	print('Impossible')
	exit()
if Z == 0 and k > L:
	print('Impossible')
	exit()
if k > L:
	i = s.find('*')
	s = s.replace('*', s[i - 1] * (k - L), 1)
s = s.replace('*', '?')
for i in range(L - k):
	i = s.find('?')
	s = s.replace(s[i - 1] + '?', '', 1)
s = s.replace('?', '')
print(s)


s = input()
n = int(input())
ans = ''
k = 0
n1 = len(s)
(c1, c2) = (0, 0)
for i in s:
	if i == '?':
		c1 += 1
	elif i == '*':
		c2 += 1
	else:
		k += 1
if n < k - (c1 + c2):
	print('Impossible')
elif c2 == 0 and n > k:
	print('Impossible')
elif n >= k - (c1 + c2) and n <= k:
	d = k - n
	for i in range(n1 - 1):
		if (s[i + 1] == '?' or s[i + 1] == '*') and d == 0:
			ans += s[i]
		elif s[i + 1] == '?' or s[i + 1] == '*':
			d -= 1
		elif s[i] != '?' and s[i] != '*':
			ans += s[i]
	if s[n1 - 1] != '?' and s[n1 - 1] != '*':
		ans += s[n1 - 1]
	print(ans)
else:
	d = n - k
	for i in range(n1 - 1):
		if s[i] != '?' and s[i] != '*':
			ans += s[i]
		if s[i + 1] == '*' and d != 0:
			ans += s[i] * d
			d = 0
	if s[n1 - 1] != '?' and s[n1 - 1] != '*':
		ans += s[n1 - 1]
	print(ans)


t = input()
k = int(input())
b = 0
x = 0
y = 0
c = str('')
d = str('')
for i in range(len(t)):
	if t[i] == '?':
		x += 1
	elif t[i] == '*':
		y += 1
	else:
		b += 1
if k < b - (x + y):
	print('Impossible')
else:
	for i in range(len(t)):
		if t[i] == '?':
			if k < b:
				c = c[:-1]
				b -= 1
		elif t[i] == '*':
			if k < b:
				c = c[:-1]
				b -= 1
			else:
				c += t[i]
		else:
			c += t[i]
		w = -1
	if y > 0 and k != b:
		for i in range(len(c)):
			if c[i] == '*':
				r = d[w]
				while k > b:
					d += r
					w += 1
					b += 1
			else:
				d += c[i]
				w += 1
		print(d)
	elif k == b:
		for i in range(len(c)):
			if c[i] != '*':
				d += c[i]
		print(d)
	else:
		print('Impossible')


s = input()
n = int(input())
c = 0
for i in range(len(s)):
	if s[i] != '*' and s[i] != '?':
		c += 1
ans = ''
if c <= n:
	z = 0
	for i in range(len(s)):
		if s[i] != '*' and s[i] != '?':
			ans += s[i]
		else:
			if z == 1:
				continue
			if s[i] == '*':
				ans += s[i - 1] * (n - c)
				z = 1
else:
	k = c - n
	for i in range(len(s)):
		if s[i] != '*' and s[i] != '?':
			ans += s[i]
		elif k == 0:
			continue
		else:
			ans = ans[:len(ans) - 1]
			k -= 1
if n == len(ans):
	print(ans)
else:
	print('Impossible')


s = input()
k = int(input())
n = len(s)
f = 0
a = []
c = 0
if s.count('*') >= 1:
	f = 1
if s.count('?') >= 1:
	c = 1
if n > k and f == 1:
	a = []
	n = n - 2 * (s.count('?') + s.count('*'))
	if n > k:
		print('Impossible')
	else:
		x = k - n
		var = 0
		for i in range(len(s)):
			if s[i] == '*' and var == 0:
				a.pop()
				for j in range(x):
					a.append(s[i - 1])
				var = 1
			elif s[i] == '*' and var == 1:
				a.pop()
			elif s[i] == '?':
				a.pop()
			else:
				a.append(s[i])
		for i in range(len(a)):
			print(a[i], end='')
elif n > k and f == 0:
	a = []
	if n - 2 * (s.count('?') + s.count('*')) <= k and k <= n - (s.count('?') + s.count('*')):
		x = n - s.count('?') - k
		for i in range(len(s)):
			if s[i] == '?' and x > 0:
				a.pop()
				x += -1
			elif s[i] == '?' and x == 0:
				pass
			else:
				a.append(s[i])
		for i in range(len(a)):
			print(a[i], end='')
	else:
		print('Impossible')
elif n <= k and f == 1:
	var = 0
	x = k - n + 2 * (s.count('?') + s.count('*'))
	for i in range(len(s)):
		if s[i] == '*' and var == 0:
			a.pop()
			for j in range(x):
				a.append(s[i - 1])
			var = 1
		elif s[i] == '*' and var == 1:
			a.pop()
		elif s[i] == '?':
			a.pop()
		else:
			a.append(s[i])
	for i in range(len(a)):
		print(a[i], end='')
elif n < k and f == 0:
	print('Impossible')
elif n == k and f == 0 and (c == 0):
	print(s)


s = input()
t = int(input())
count = 0
x = []
y = []
for k in s:
	if k == '*' or k == '?':
		count = count + 1
	x.append(k)
if t >= len(x) - 2 * count:
	if len(x) - count > t:
		w = len(x) - count - t
		j = i = 0
		while j < len(x):
			if x[j] == '*' or x[j] == '?':
				w = w - 1
				y.pop()
				if w == 0:
					j = j + 1
					break
			else:
				y.append(x[j])
			j = j + 1
		while j < len(x):
			if x[j] == '*' or x[j] == '?':
				j = j + 1
			else:
				y.append(x[j])
				j = j + 1
		s = ''.join(y)
		print(s)
	elif len(x) - count == t:
		j = 0
		while j < len(x):
			if x[j] == '*' or x[j] == '?':
				j = j + 1
			else:
				y.append(x[j])
				j = j + 1
		s = ''.join(y)
		print(s)
	elif '*' in x:
		j = 0
		while j < len(x):
			if x[j] == '*':
				w1 = t - (len(x) - count)
				i = 0
				while i < w1:
					y.append(x[j - 1])
					i = i + 1
				if i == w1:
					break
				j = j + 1
			elif x[j] == '?':
				j = j + 1
			else:
				y.append(x[j])
				j = j + 1
		while j < len(x):
			if x[j] == '*' or x[j] == '?':
				j = j + 1
			else:
				y.append(x[j])
				j = j + 1
		s = ''.join(y)
		print(s)
	else:
		print('Impossible')
else:
	print('Impossible')


msg = str(input())
l = len(msg)
k = int(input())
cc = msg.count('?')
sf = msg.count('*')
chara = l - cc - sf
l_min = chara - cc - sf
l_max = chara + sf * 200
if l_min > k or l_max < k:
	print('Impossible')
elif chara == k:
	ans = msg.replace('?', '')
	ans = ans.replace('*', '')
	print(ans)
elif sf != 0:
	ans = msg
	for i in range(0, cc):
		x = ans.find('?')
		new_ans = ans[0:x - 1]
		new_ans += ans[x + 1:]
		ans = new_ans
	for i in range(0, sf - 1):
		x = ans.find('*')
		new_ans = ans[0:x - 1]
		new_ans += ans[x + 1:]
		ans = new_ans
	x = ans.find('*')
	l_cnt = len(ans)
	pre_x = ans[x - 1:x]
	new_ans = ans[0:x - 1]
	for tmp in range(0, k - l_cnt + 2):
		new_ans += pre_x
	new_ans += ans[x + 1:]
	ans = new_ans
	if len(ans) == k:
		print(ans)
	else:
		print('ERRRRRRR')
else:
	ans = msg
	while len(ans.replace('?', '')) != k:
		x = ans.find('?')
		new_ans = ans[0:x - 1]
		new_ans += ans[x + 1:]
		ans = new_ans
	print(ans.replace('?', ''))


o = input()
s = [x for x in o]
r = [x for x in o]
n = int(input())
l = s.count('?')
m = s.count('*')
c = len(s) - l - m
if n > c and m == 0 or n < c - l - m:
	print('Impossible')
elif n == c:
	for i in range(len(s)):
		if s[i] == '?' or s[i] == '*':
			continue
		else:
			print(s[i], end='')
elif n < c:
	l = c - n
	for i in range(1, len(s)):
		if l > 0 and (s[i] == '?' or s[i] == '*'):
			l = l - 1
		elif l > 0 and (s[i - 1] != '?' and s[i - 1] != '*'):
			print(s[i - 1], end='')
			continue
		elif l == 0 and (s[i] == '?' or s[i] == '*'):
			continue
		elif l == 0:
			print(s[i], end='')
elif n > c:
	l = n - c
	d = 0
	for i in range(len(s)):
		if s[i] == '?':
			continue
		elif s[i] == '*' and l > 0:
			for r in range(l):
				print(s[i - 1], end='')
			l = 0
		elif s[i] == '*' and l == 0:
			continue
		else:
			print(s[i], end='')


def calChars(string):
	count = 0
	for i in string:
		if i != '*' and i != '?':
			count += 1
	return count

def candyCones(string):
	return string.count('?')

def snowFlakes(string):
	return string.count('*')

def cstr(string):
	ans = ''
	for i in string:
		if i != '?' and i != '*':
			ans += i
	return ans

def newString(string):
	ans = ''
	for i in string:
		if i == '?' or i == '*':
			ans += '?'
		else:
			ans += i
	return ans

def main():
	string = input()
	chars = calChars(string)
	candyCone = candyCones(string)
	snowFlake = snowFlakes(string)
	k = int(input())
	length = len(string)
	ans = ''
	if k == chars:
		for i in string:
			if i != '?' and i != '*':
				ans += i
		if len(ans) == k:
			print(ans)
			return
		else:
			print('Impossible')
			return
	elif k < chars:
		diff = chars - k
		start = 0
		string = newString(string)
		while diff != 0:
			end = string.find('?', start)
			ans += string[start:end - 1]
			start = end + 1
			diff -= 1
		ans += string[start:]
		ans = cstr(ans)
		if len(ans) == k:
			print(ans)
			return
		else:
			print('Impossible')
			return
	else:
		start = 0
		end = string.find('*')
		if end == -1:
			print('Impossible')
			return
		else:
			ans = string[:end - 1]
			ans += string[end - 1] * (k - chars + 1)
			ans += string[end + 1:]
		ans = cstr(ans)
		if len(ans) == k:
			print(ans)
			return
		else:
			print('Impossible')
			return
main()


s = input()
k = int(input())
ns = ''
req = 0
dic = {'?': 0, '*': 0}
for i in s:
	if i == '?':
		dic[i] += 1
		req -= 1
	elif i == '*':
		dic[i] += 1
		req -= 1
	else:
		req += 1
if dic['?'] + dic['*'] == 0 and k == len(s):
	print(s)
	exit()
if dic['?'] + dic['*'] == 0 or (dic['*'] == 0 and dic['?'] + req < k) or req > k:
	print('Impossible')
else:
	res = []
	D = k - req
	for i in range(len(s)):
		if s[i] == '?' or s[i] == '*':
			continue
		if i != len(s) - 1 and s[i] != '?' and (s[i] != '*') and (s[i + 1] != '?') and (s[i + 1] != '*'):
			res.append(s[i])
		elif i == len(s) - 1 and s[i] != '?' and (s[i] != '*'):
			res.append(s[i])
		elif i != len(s) - 1 and s[i] != '?' and (s[i] != '*') and (s[i + 1] == '?' or s[i + 1] == '*'):
			if D == 0:
				continue
			elif D > 0:
				if s[i + 1] == '*':
					for _ in range(D):
						res.append(s[i])
					D = 0
				else:
					res.append(s[i])
					D -= 1
	print(''.join(res))


s = input()
n = int(input())
loc_j = []
loc_x = []
j = s.count('?')
x = s.count('*')
now = len(s)
delta = now - (x + j)
if delta == n:
	s = s.replace('?', '')
	s = s.replace('*', '')
	print(s)
elif delta >= n:
	if delta - n > x + j:
		print('Impossible')
	elif delta - n == x + j:
		s = list(s)
		i = 0
		while i < len(s):
			if s[i] == '?' or s[i] == '*':
				del s[i]
				i -= 1
			elif i != len(s) - 1:
				if s[i + 1] == '?' or s[i + 1] == '*':
					del s[i]
					i -= 1
			i += 1
		print(''.join(s))
	elif delta - n < x + j:
		need = delta - n
		s = list(s)
		i = 0
		c = 0
		while c < need:
			if s[i] == '?' or s[i] == '*':
				del s[i]
				i -= 1
			elif i != len(s) - 1:
				if s[i + 1] == '?' or s[i + 1] == '*':
					del s[i]
					i -= 1
					c += 1
			i += 1
		s = ''.join(s)
		s = s.replace('?', '')
		s = s.replace('*', '')
		print(s)
elif x == 0:
	print('Impossible')
else:
	need = n - delta
	s = s.replace('?', '')
	s = list(s)
	now = len(s)
	for i in range(now):
		if i != len(s) - 1:
			if s[i + 1] == '*':
				f = 0
				while f < need:
					s.insert(i, s[i])
					f += 1
				break
	s = ''.join(s)
	s = s.replace('*', '')
	print(s)


from sys import stdin
import math

def get_normal_length(string):
	l = 0
	for i in string:
		if i != '*' and i != '?':
			l += 1
	return l

def get_special(string):
	count = 0
	for i in string:
		if i == '?' or i == '*':
			count += 1
	return count
string = list(stdin.readline().strip())
n = len(string)
k = int(stdin.readline().strip())
normal = get_normal_length(string)
if k > normal:
	if '*' in string:
		diff = k - normal
		flag = False
		for i in range(len(string)):
			if string[i] == '?':
				continue
			elif string[i] == '*':
				if flag == False:
					flag = True
					for _ in range(diff):
						print(string[i - 1], end='')
			else:
				print(string[i], end='')
	else:
		print('Impossible')
		exit()
elif k < normal:
	if '*' in string or '?' in string:
		diff = normal - k
		number = get_special(string)
		if number >= diff:
			i = 0
			count = 0
			while i < n and count < diff:
				if string[i] != '*' and string[i] != '?':
					try:
						if string[i + 1] == '*' or string[i + 1] == '?':
							i += 2
							count += 1
							continue
						else:
							print(string[i], end='')
							i += 1
							continue
					except:
						print(string[i], end='')
						i += 1
						continue
				i += 1
			if i < n:
				while i < n:
					if string[i] != '*' and string[i] != '?':
						print(string[i], end='')
					i += 1
			exit()
		else:
			print('Impossible')
			exit()
	else:
		print('Impossible')
		exit()
else:
	for i in string:
		if i != '?' and i != '*':
			print(i, end='')


from collections import deque as de
import math
import re
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr
from bisect import bisect_left as bl, bisect_right as br

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

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

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

def binarytodecimal(n):
	return int(n, 2)

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 get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def dupconscount(nums):
	element = []
	freque = []
	if not nums:
		return element
	running_count = 1
	for i in range(len(nums) - 1):
		if nums[i] == nums[i + 1]:
			running_count += 1
		else:
			freque.append(running_count)
			element.append(nums[i])
			running_count = 1
	freque.append(running_count)
	element.append(nums[i + 1])
	return (element, freque)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y

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

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

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

def si():
	return list(map(str, input()))

def indic():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(value)] = int(index) + 1
	return dic
s = si()
k = ii()
sfcnt = s.count('*')
cncnt = s.count('?')
netlen = len(s) - sfcnt - cncnt
if k > netlen:
	ans = ''
	ch = 1
	netaddk = k - netlen
	for i in range(len(s)):
		if s[i] != '*' and s[i] != '?':
			ans += s[i]
		elif s[i] == '*':
			if ch:
				ans += s[i - 1] * netaddk
				ch = 0
elif k < netlen:
	ans = ''
	netsub = netlen - k
	for i in range(len(s) - 1):
		if netsub and (s[i + 1] == '*' or s[i + 1] == '?'):
			pass
			netsub -= 1
		elif s[i] != '*' and s[i] != '?':
			ans += s[i]
	if s[len(s) - 1] != '*' and s[len(s) - 1] != '?':
		ans += s[len(s) - 1]
else:
	ans = ''
	for i in range(len(s)):
		if s[i] != '?' and s[i] != '*':
			ans += s[i]
if len(ans) == k:
	print(ans)
else:
	print('Impossible')


from collections import Counter
s = input()
n = int(input())
c = Counter(s)
l = len(s) - c['?'] - c['*']
if n < l - c['?'] - c['*']:
	print('Impossible')
elif n <= l:
	d = l - n
	r = []
	for (u, v) in zip(s, s[1:] + ' '):
		if v in '?*' and d:
			d -= 1
		elif u not in '?*':
			r.append(u)
	print(''.join(r))
elif c['*'] > 0:
	d = n - l
	i = s.index('*')
	print((s[:i] + s[i - 1] * d + s[i:]).replace('?', '').replace('*', ''))
else:
	print('Impossible')


s = input()
k = int(input())
k1 = 0
k2 = 0
n = 0
for char in s:
	if char == '?':
		k1 += 1
	elif char == '*':
		k2 += 1
	else:
		n += 1
min_length = n - k1 - k2
if k2 == 0:
	max_length = n
else:
	max_length = k + 1
final_chars = list()
if k >= min_length and k <= max_length:
	if k <= n:
		num_chars_to_remove = n - k
		num_removed = 0
		for char in s:
			if char == '?' or char == '*':
				if num_removed < num_chars_to_remove:
					final_chars.pop()
					num_removed += 1
				else:
					pass
			else:
				final_chars.append(char)
		print(''.join(final_chars))
	else:
		rev_string = s[::-1]
		curr_idx = 0
		found = 0
		num_chars_to_add = k - n
		while curr_idx < len(rev_string):
			if rev_string[curr_idx].isalpha():
				final_chars.append(rev_string[curr_idx])
				curr_idx += 1
			elif rev_string[curr_idx] == '*' and (not found):
				found = 1
				next_char = rev_string[curr_idx + 1]
				for i in range(num_chars_to_add):
					final_chars.append(next_char)
				curr_idx += 1
			else:
				curr_idx += 1
		final_chars = final_chars[::-1]
		print(''.join(final_chars))
else:
	print('Impossible')


class lett:

	def __init__(self, v, p=None):
		self.val = v
		self.prev = p
c = {}
s = str(input())
k = int(input())
c[0] = lett(s[0])
n = 1
sn = 0
cn = 0
l = len(s)
for i in range(1, l):
	c[i] = lett(s[i], s[i - 1])
	if s[i] == '*':
		sn += 1
	elif s[i] == '?':
		cn += 1
	else:
		n += 1
ans = ''
if sn == 0 and n < k or k < n - (sn + cn):
	print('Impossible')
else:
	if k < n:
		i = l - 1
		supr = n - k
		while i >= 0:
			if supr == 0:
				if c[i].val in ['?', '*']:
					i -= 1
				else:
					ans = c[i].val + ans
					i -= 1
			elif c[i].val in ['?', '*']:
				supr -= 1
				i -= 2
			else:
				ans = c[i].val + ans
				i -= 1
	else:
		i = l - 1
		supr = k - n + 1
		b = True
		while i >= 0:
			if c[i].val == '*' and b:
				ans = c[i - 1].val * supr + ans
				b = False
				i -= 2
			elif b:
				if c[i].val == '?':
					i -= 1
				else:
					ans = c[i].val + ans
					i -= 1
			elif c[i].val in ['?', '*']:
				i -= 1
			else:
				ans = c[i].val + ans
				i -= 1
	print(ans)


s = input()
k = int(input())
n = len(s)
if n == 0:
	print('Impossible')
	exit()
count = 0
for x in s:
	if x == '*' or x == '?':
		count += 1
t = n - count
if t == k:
	res = ''
	for x in s:
		if x != '*' and x != '?':
			res += x
	print(res)
elif t < k:
	e = k - t
	res = ''
	for i in range(1, n):
		if s[i] == '*':
			if e != 0:
				res += s[i - 1] * (e + 1)
				e = 0
			else:
				res += s[i - 1]
		elif s[i - 1] != '?' and s[i - 1] != '*':
			res += s[i - 1]
	if s[-1] not in ['*', '?']:
		res += s[-1]
	if e == 0:
		print(res)
	else:
		print('Impossible')
else:
	e = t - k
	res = ''
	for i in range(1, n):
		if s[i] == '*' or s[i] == '?':
			if e != 0:
				e -= 1
			else:
				res += s[i - 1]
		elif s[i - 1] not in ['*', '?']:
			res += s[i - 1]
	if s[-1] not in ['*', '?']:
		res += s[-1]
	if e == 0:
		print(res)
	else:
		print('Impossible')


import math
from collections import deque

def get_res(S, N):
	X = set(['*', '?'])
	L = [ch for ch in S]
	L1 = [ch for ch in S if ch not in X]
	L2 = [ch for ch in S if ch in X]
	low = len(L1) - len(L2)
	if N < low:
		return 'Impossible'
	if N == len(L1):
		return ''.join(L1)
	if N > len(L1):
		if '*' not in set(L2):
			return 'Impossible'
		else:
			first_flake = 0
			cnt = 0
			for ch in S:
				if ch == '*':
					break
				cnt += 1
			ch = S[cnt - 1]
			res = S[0:cnt] + ch * (N - len(L1)) + S[cnt:]
			result = ''
			for ch in res:
				if ch not in X:
					result += ch
			return result
	result = ''
	rem = len(L1) - N
	for i in range(len(L)):
		if rem > 0 and L[i] in X:
			L[i - 1] = L[i]
			rem -= 1
	S = ''.join(L)
	for ch in S:
		if ch not in X:
			result += ch
	return result
S = input()
N = int(input())
result = get_res(S, N)
print('{}'.format(result))


import os, sys
from io import IOBase, BytesIO
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log, pi, sin
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outarr(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val):
	return [val for i in range(n)]

def l2d(n, m, val):
	return [l1d(m, val) for j in range(n)]
s = data()
k = int(data())
answer = []
n = len(s) - s.count('*') - s.count('?')
for i in s:
	if i == '?':
		if n > k and answer:
			answer.pop()
			n -= 1
	elif i == '*':
		if n < k:
			for temp in range(k - n):
				answer.append(answer[-1])
			n = k
		if n > k and answer:
			answer.pop()
			n -= 1
	else:
		answer.append(i)
if n == k:
	out(''.join(answer))
	exit()
out('Impossible')


s = list(input())
n = int(input())
ass = 0
ques = 0
let = 0
ans = []
for i in range(len(s)):
	if s[i] == '*':
		ass += 1
	elif s[i] == '?':
		ques += 1
	else:
		let += 1
if ass == 0:
	let = let - n
	for i in range(len(s)):
		if let > 0 and s[i] == '?':
			s[i - 1] = '?'
			let -= 1
	for i in range(len(s)):
		if s[i] != '?' and s[i] != '*':
			ans.append(s[i])
	if n == len(ans):
		print(''.join(ans))
	else:
		print('Impossible')
else:
	for i in range(len(s)):
		if let > 0 and s[i] == '?':
			s[i - 1] = '?'
			let -= 1
	if let == n:
		for i in range(len(s)):
			if s[i] != '?' and s[i] != '*':
				ans.append(s[i])
	elif let > n:
		let = let - n
		for i in range(len(s)):
			if let > 0 and s[i] == '*':
				s[i - 1] = '?'
				let -= 1
		for i in range(len(s)):
			if s[i] != '?' and s[i] != '*':
				ans.append(s[i])
	else:
		let = n - let
		for i in range(len(s)):
			if s[i] == '*':
				k = i - 1
				break
		for i in range(len(s)):
			if i == k:
				for j in range(let + 1):
					ans.append(s[i])
			elif s[i] != '?' and s[i] != '*':
				ans.append(s[i])
	if n == len(ans):
		print(''.join(ans))
	else:
		print('Impossible')


st = input()
n = int(input())
x = 0
k = 0
answer = ''
for ch in st:
	if ch == '?':
		x += 1
	if ch == '*':
		x += 1
for ch in st:
	if ch == '?':
		if len(st) - x + k > n:
			answer = answer[0:len(answer) - 1]
			k -= 1
	elif ch == '*':
		if len(st) - x + k > n:
			answer = answer[0:len(answer) - 1]
			k -= 1
		elif len(st) - x + k < n:
			for i in range(n - (len(st) - x + k)):
				answer += answer[len(answer) - 1:len(answer)]
				k += 1
	else:
		answer += ch
if len(answer) == n:
	print(answer)
else:
	print('Impossible')


def text():
	return ''.join(msg).replace('*', '').replace('?', '')
msg = list(input())
lenght = int(input())
if len(text()) < lenght:
	x = 0
	while x < len(msg) and len(text()) < lenght:
		if msg[x] == '*':
			msg.insert(x, msg[x - 1])
		x += 1
		if x == len(msg) and len(text()) < lenght:
			x == 0
elif len(text()) > lenght:
	x = 0
	while x < len(msg) and len(text()) > lenght:
		if msg[x] == '?' or msg[x] == '*':
			del msg[x]
			del msg[x - 1]
			x -= 1
		else:
			x += 1
if len(text()) != lenght:
	print('Impossible')
else:
	msg = ''.join(msg)
	print(text())


from math import *
from itertools import *
from collections import *
from functools import reduce

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

def input_floats():
	return map(float, input().split())

def input_strings():
	return input().split()
message = input()
k = int(input())
n_snowflake = message.count('*')
n_candy = message.count('?')
len_message = len(message)
n_chars = len_message - n_snowflake - n_candy
min_length = n_chars - (n_snowflake + n_candy)
if k < min_length or (n_snowflake == 0 and k > n_chars):
	print('Impossible')
else:
	diff = k - n_chars
	answer = ''
	for i in range(len(message) - 1):
		if message[i].isalpha():
			next_char = message[i + 1]
			if next_char == '?':
				if diff < 0:
					diff += 1
				else:
					answer += message[i]
			elif next_char == '*':
				if diff < 0:
					diff += 1
				elif diff > 0:
					answer += (diff + 1) * message[i]
					diff = 0
				else:
					answer += message[i]
			else:
				answer += message[i]
	if message[-1].isalpha():
		answer += message[-1]
	print(answer)


data = input()
k = int(input())
string = []
stick = []
star = []
pos = 0
for q in data:
	if q == '?':
		stick.append(pos)
	elif q == '*':
		star.append(pos)
	else:
		string.append(q)
		pos += 1
length = len(string)
if length == k:
	print(''.join(string))
elif length < k:
	if len(star) == 0:
		print('Impossible')
	else:
		cnt = k - length + 1
		ans = ''
		pivot = star[0]
		for q in range(length):
			if q == pivot - 1:
				temp = string[q] * cnt
				ans += temp
			else:
				ans += string[q]
		print(ans)
else:
	cnt = length - k
	if cnt <= len(star) + len(stick):
		ans = ''
		flag = 0
		for q in range(len(data)):
			if cnt == 0:
				flag = 1
			if not flag:
				if data[q] == '?' or data[q] == '*':
					continue
				if data[q + 1] == '?' or data[q + 1] == '*':
					cnt -= 1
				else:
					ans += data[q]
			elif data[q] == '?' or data[q] == '*':
				continue
			else:
				ans += data[q]
		print(ans)
	else:
		print('Impossible')


s = input()
k = int(input())
count = 0
l = []
fixcount = 0
for i in range(len(s)):
	if s[i] != '?' and s[i] != '*':
		count += 1
for i in range(len(s) - 1):
	if s[i] != '?' and s[i] != '*' and (s[i + 1] != '?' and s[i + 1] != '*'):
		fixcount += 1
if s[-1] != '?' and s[-1] != '*':
	fixcount += 1
if count == k:
	for i in range(len(s)):
		if s[i] != '?' and s[i] != '*':
			l.append(s[i])
	print(''.join(l))
elif count < k:
	if '*' not in s:
		print('Impossible')
	else:
		flag = False
		for i in range(len(s) - 1):
			if s[i] != '?' and s[i] != '*':
				l.append(s[i])
				if s[i + 1] == '*' and flag == False:
					flag = True
					for j in range(k - count):
						l.append(s[i])
		if s[-1] != '?' and s[-1] != '*':
			l.append(s[-1])
		print(''.join(l))
elif fixcount > k:
	print('Impossible')
else:
	diff = count - k
	for i in range(len(s) - 1):
		if diff > 0 and s[i] != '?' and (s[i] != '*') and (s[i + 1] == '?' or s[i + 1] == '*'):
			diff -= 1
		elif s[i] != '?' and s[i] != '*':
			l.append(s[i])
	if s[-1] != '?' and s[-1] != '*':
		l.append(s[-1])
	if diff > 0:
		print('Impossible')
	else:
		print(''.join(l))


s = input()
n = int(input())
l = len(s)
remove = s.count('?') + s.count('*')
el = l - remove
ans = ''
if el > n and el - remove > n:
	print('Impossible')
	exit()
elif el >= n:
	deleted = 0
	for c in s:
		if (c == '?' or c == '*') and deleted < el - n:
			ans = ans[:-1]
			deleted += 1
		elif c != '?' and c != '*':
			ans += c
elif el < n and '*' not in s:
	print('Impossible')
	exit()
else:
	added = False
	for c in s:
		if c != '*' and c != '?':
			ans += c
		elif c == '*' and (not added):
			ans += ans[-1] * (n - el)
			added = True
print(ans)


r = input()
count1 = 0
count2 = 0
count3 = 0
n = len(r)
for i in range(0, len(r) - 1):
	if r[i] == '?':
		count2 = count2 + 1
		continue
	if r[i] == '*':
		count3 = count3 + 1
		continue
	if r[i + 1] != '?' and r[i + 1] != '*':
		count1 = count1 + 1
if r[len(r) - 1] == '?':
	count2 = count2 + 1
elif r[n - 1] == '*':
	count3 = count3 + 1
else:
	count1 = count1 + 1
r = r + 'a'
k = int(input())
if k < count1:
	print('Impossible')
	exit(0)
if count3 >= 1:
	f = 0
	ans = ''
	for i in range(0, len(r) - 1):
		if r[i] == '?':
			continue
		if r[i] == '*':
			continue
		if r[i + 1] == '?':
			continue
		if r[i + 1] == '*' and f == 0:
			ans = ans + r[i] * (k - count1)
			f = 1
			continue
		if r[i + 1] == '*' and f == 1:
			continue
		ans = ans + r[i]
	print(ans)
	exit(0)
y = k - count1
ans = ''
for i in range(0, len(r) - 1):
	if r[i] == '?':
		continue
	if r[i + 1] == '?' and y > 0:
		ans = ans + r[i]
		y = y - 1
		continue
	if r[i + 1] == '?':
		continue
	ans = ans + r[i]
if y > 0:
	print('Impossible')
else:
	print(ans)


s = list(input())
k = int(input())
l = len(s) - s.count('*') - s.count('?')
i = 0
if k < l:
	while i < len(s) and k != l and ('*' in s or '?' in s):
		if s[i] == '?' or s[i] == '*':
			del s[i - 1:i + 1]
			l -= 1
		else:
			i += 1
	if k != l:
		print('Impossible')
	else:
		st = ''.join(s)
		st = st.replace('*', '')
		st = st.replace('?', '')
		print(st)
elif k > l:
	while k != l and '*' in s:
		if s[i] == '*':
			while k != l:
				s.insert(i, s[i - 1])
				k -= 1
		i += 1
	if k != l:
		print('Impossible')
	else:
		st = ''.join(s)
		st = st.replace('*', '')
		st = st.replace('?', '')
		print(st)
else:
	st = ''.join(s)
	st = st.replace('*', '')
	st = st.replace('?', '')
	print(st)


import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
BUFSIZE = 8192

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

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

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def binarySearch(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
import os
import sys
import math
from io import BytesIO, IOBase
import io
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
from collections import Counter
import threading
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')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10001)]
prime[0] = prime[1] = False

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

class DSU:

	def __init__(self, R, C):
		self.par = range(R * C + 1)
		self.rnk = [0] * (R * C + 1)
		self.sz = [1] * (R * C + 1)

	def find(self, x):
		if self.par[x] != x:
			self.par[x] = self.find(self.par[x])
		return self.par[x]

	def union(self, x, y):
		(xr, yr) = (self.find(x), self.find(y))
		if xr == yr:
			return
		if self.rnk[xr] < self.rnk[yr]:
			(xr, yr) = (yr, xr)
		if self.rnk[xr] == self.rnk[yr]:
			self.rnk[xr] += 1
		self.par[yr] = xr
		self.sz[xr] += self.sz[yr]

	def size(self, x):
		return self.sz[self.find(x)]

	def top(self):
		return self.size(len(self.sz) - 1) - 1

class LazySegTree:

	def __init__(self, _op, _e, _mapping, _composition, _id, v):

		def set(p, x):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			_d[p] = x
			for i in range(1, _log + 1):
				_update(p >> i)

		def get(p):
			assert 0 <= p < _n
			p += _size
			for i in range(_log, 0, -1):
				_push(p >> i)
			return _d[p]

		def prod(l, r):
			assert 0 <= l <= r <= _n
			if l == r:
				return _e
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r >> i)
			sml = _e
			smr = _e
			while l < r:
				if l & 1:
					sml = _op(sml, _d[l])
					l += 1
				if r & 1:
					r -= 1
					smr = _op(_d[r], smr)
				l >>= 1
				r >>= 1
			return _op(sml, smr)

		def apply(l, r, f):
			assert 0 <= l <= r <= _n
			if l == r:
				return
			l += _size
			r += _size
			for i in range(_log, 0, -1):
				if l >> i << i != l:
					_push(l >> i)
				if r >> i << i != r:
					_push(r - 1 >> i)
			l2 = l
			r2 = r
			while l < r:
				if l & 1:
					_all_apply(l, f)
					l += 1
				if r & 1:
					r -= 1
					_all_apply(r, f)
				l >>= 1
				r >>= 1
			l = l2
			r = r2
			for i in range(1, _log + 1):
				if l >> i << i != l:
					_update(l >> i)
				if r >> i << i != r:
					_update(r - 1 >> i)

		def _update(k):
			_d[k] = _op(_d[2 * k], _d[2 * k + 1])

		def _all_apply(k, f):
			_d[k] = _mapping(f, _d[k])
			if k < _size:
				_lz[k] = _composition(f, _lz[k])

		def _push(k):
			_all_apply(2 * k, _lz[k])
			_all_apply(2 * k + 1, _lz[k])
			_lz[k] = _id
		_n = len(v)
		_log = _n.bit_length()
		_size = 1 << _log
		_d = [_e] * (2 * _size)
		_lz = [_id] * _size
		for i in range(_n):
			_d[_size + i] = v[i]
		for i in range(_size - 1, 0, -1):
			_update(i)
		self.set = set
		self.get = get
		self.prod = prod
		self.apply = apply
MIL = 1 << 20

def makeNode(total, count):
	return total * MIL + count

def getTotal(node):
	return math.floor(node / MIL)

def getCount(node):
	return node - getTotal(node) * MIL
nodeIdentity = makeNode(0.0, 0.0)

def nodeOp(node1, node2):
	return node1 + node2
	return makeNode(getTotal(node1) + getTotal(node2), getCount(node1) + getCount(node2))
identityMapping = -1

def mapping(tag, node):
	if tag == identityMapping:
		return node
	count = getCount(node)
	return makeNode(tag * count, count)

def composition(mapping1, mapping2):
	return mapping1 if mapping1 != identityMapping else mapping2

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return math.gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = math.gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = math.gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small

def binarySearch(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = n
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			res = mid
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, i, key):
	left = 0
	right = n - 1
	mid = 0
	res = -1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid][i] > key:
			right = mid - 1
		else:
			res = mid
			left = mid + 1
	return res
t = 1
for _ in range(t):
	s = input()
	n = len(s)
	k = int(input())
	(candy, snow, letters) = (0, 0, 0)
	s = list(s)
	for i in s:
		if i == '?':
			candy += 1
		elif i == '*':
			snow += 1
		else:
			letters += 1
	if k > letters:
		if snow:
			req = k - letters
			a = []
			for i in range(n):
				if s[i] == '?':
					continue
				if s[i] == '*':
					for j in range(req):
						a.append(s[i - 1])
					req = 0
				else:
					a.append(s[i])
			print(*a, sep='')
		else:
			print('Impossible')
	elif k <= letters:
		if letters - (candy + snow) > k:
			print('Impossible')
		else:
			delete = letters - k
			a = []
			for i in range(n):
				if s[i] == '?' or s[i] == '*':
					if delete:
						a.pop()
						delete -= 1
				else:
					a.append(s[i])
			print(*a, sep='')


def solve():
	if n > co:
		k = 0
		r = 0
		for i in range(len(s)):
			if s[i] == '*':
				k = i - 1
				break
		for i in range(len(s)):
			if k == i:
				print(s[i] * (n - co + 1), end='')
			elif s[i] != '*' and s[i] != '?':
				print(s[i], end='')
	elif n < co:
		d = dict()
		rar = 0
		for i in range(len(s)):
			if (s[i] == '*' or s[i] == '?') and rar != co - n:
				d[i - 1] = 1
				rar += 1
		for i in range(len(s)):
			if i not in d and s[i] != '*' and (s[i] != '?'):
				print(s[i], end='')
	else:
		for i in range(len(s)):
			if s[i] != '*' and s[i] != '?':
				print(s[i], end='')
s = input().strip()
n = int(input())
co = 0
yap1 = 0
yap2 = 0
for i in range(len(s)):
	if s[i] != '*' and s[i] != '?':
		co += 1
	elif s[i] == '*':
		yap2 += 1
	elif s[i] == '?':
		yap1 += 1
if n > co:
	if yap2 == 0:
		print('Impossible')
	else:
		solve()
elif n < co:
	if co - (yap1 + yap2) > n:
		print('Impossible')
	else:
		solve()
else:
	solve()


x = input()
b = eval(input())
i = 0
candys = 0
stars = 0
while i < len(x):
	if x[i] == '?':
		candys += 1
		i += 1
	elif x[i] == '*':
		stars += 1
		i += 1
	else:
		i += 1
string = len(x) - candys - stars
i = 0
a = ''
while i < len(x):
	if string == b:
		if x[i] != '?' and x[i] != '*':
			a += x[i]
			i += 1
		else:
			i += 1
	elif string > b:
		while i < len(x) - 1 and string > b:
			if x[i + 1] == '?' or x[i + 1] == '*':
				i += 2
				string -= 1
			else:
				a += x[i]
				i += 1
		if i == len(x) - 1:
			a += x[i]
			i += 1
	elif string < b:
		if x[i] == '*':
			c = b - int(string)
			a += c * x[i - 1]
			i += 1
			string += c
		elif x[i] == '?':
			i += 1
		else:
			a += x[i]
			i += 1
if len(a) == b:
	print(a)
else:
	print('Impossible')


st = list(input())
k = int(input())
le = len(st)
can = st.count('?')
sno = st.count('*')
ext = le - can - sno - k
if ext < 0:
	if sno == 0:
		print('Impossible')
	else:
		fin = st.index('*')
		st.insert(fin, abs(ext) * st[fin - 1])
		for i in st:
			if i != '?' and i != '*':
				print(i, end='')
elif ext >= 0:
	if ext > sno + can:
		print('Impossible')
	else:
		stco = st.copy()
		for i in range(le):
			if st[i] == '?' or st[i] == '*':
				if ext != 0:
					stco[i - 1] = ''
					stco[i] = ''
					ext -= 1
				else:
					stco[i] = ''
		print(''.join(stco))


encod = input()
tam = int(input())
cert = encod.replace('?', '').replace('*', '')
if len(cert) == tam:
	print(cert)
elif len(cert) > tam:
	r = ''
	p = 0
	x = len(cert) - tam
	for i in encod:
		if i == '?' or i == '*':
			if p < x:
				r = r[:len(r) - 1]
				p += 1
		else:
			r += i
	if len(r) > tam:
		print('Impossible')
	else:
		print(r)
else:
	x = tam - len(cert)
	p = 0
	r = ''
	for i in encod:
		if i == '*':
			if x != 0:
				r += r[len(r) - 1] * x
				x = 0
		elif i != '?':
			r += i
	if len(r) < tam:
		print('Impossible')
	else:
		print(r)


s = input()
k = int(input())
count = 0
for c in s:
	if c == '?' or c == '*':
		count += 1
if len(s) - count == k:
	s = s.replace('?', '')
	s = s.replace('*', '')
	print(s)
elif k < len(s) - count:
	if k < len(s) - 2 * count:
		print('Impossible')
	else:
		for _ in range(len(s) - count - k):
			for i in range(len(s)):
				if s[i] == '?' or s[i] == '*':
					s = s[:i - 1] + s[i + 1:]
					break
		s = s.replace('?', '')
		s = s.replace('*', '')
		print(s)
elif '*' not in s:
	print('Impossible')
else:
	for _ in range(k - (len(s) - count)):
		for i in range(len(s)):
			if s[i] == '*':
				s = s[:i] + s[i - 1] + s[i:]
				break
	s = s.replace('?', '')
	s = s.replace('*', '')
	print(s)


s = input()
n = int(input())
a = int(0)
b = int(0)
for i in range(len(s)):
	if s[i] == '?':
		a += 1
	elif s[i] == '*':
		b += 1
if len(s) - a - b == n:
	for i in range(len(s)):
		if s[i] != '*' and s[i] != '?':
			print(s[i], end='')
elif len(s) - a - b < n:
	if b > 0:
		c = n - len(s) + 1 + a + b
		x = s.index('*')
		q = s[0:x - 1] + s[x - 1] * c + s[x + 1:len(s)]
		for i in range(len(q)):
			if q[i] != '*' and q[i] != '?':
				print(q[i], end='')
	else:
		print('Impossible')
elif len(s) - n - a - b > a + b:
	print('Impossible')
else:
	z = len(s) - n - a - b
	while a > 0 and z > 0:
		f = s.index('?')
		a -= 1
		z -= 1
		if f < len(s):
			s = s[0:f - 1] + s[f + 1:]
		else:
			s = s[0:f - 1]
	while b > 0 and z > 0:
		z -= 1
		b -= 1
		f = s.index('*')
		if f < len(s):
			s = s[0:f - 1] + s[f + 1:]
		else:
			s = s[0:f - 1]
	for i in range(len(s)):
		if s[i] != '*' and s[i] != '?':
			print(s[i], end='')


s = input()
k = int(input())
x = s.count('?')
y = s.count('*')
true = len(s) - x - y
if true - x - y > k or (true < k and y == 0):
	exit(print('Impossible'))
ans = ''
if true < k:
	i = s.index('*')
	ans = s[:i] + s[i - 1] * (k - true) + s[i:]
else:
	j = 0
	cnt = 0
	for i in range(len(s) - 1):
		if cnt != true - k and s[i + 1] in ['?', '*']:
			cnt += 1
			ans += s[j:i]
			j = i + 1
	ans += s[j:]
ans = ans.replace('?', '')
ans = ans.replace('*', '')
print(ans)


def C():
	message = input()
	k = int(input())
	candy_count = 0
	snowflake_count = 0
	for char in message:
		if char == '?':
			candy_count += 1
		if char == '*':
			snowflake_count += 1
	if k < len(message) - 2 * (candy_count + snowflake_count):
		print('Impossible')
		return
	if snowflake_count == 0 and k > len(message) - candy_count:
		print('Impossible')
		return
	if k > len(message) - candy_count - snowflake_count:
		ans_start = ''
		ans_end = ''
		idx_snowflake = message.index('*')
		for char in message[:idx_snowflake]:
			if char != '?':
				ans_start += char
		for char in message[idx_snowflake:]:
			if char not in ['*', '?']:
				ans_end += char
		while k > len(message) - candy_count - snowflake_count:
			ans_start += ans_start[-1]
			k -= 1
		print(ans_start + ans_end)
		return
	if k == len(message) - candy_count - snowflake_count:
		ans = ''
		for char in message:
			if char not in ['*', '?']:
				ans += char
		print(ans)
		return
	if k < len(message) - candy_count - snowflake_count:
		ans = ''
		aux = set()
		caracteres_a_remover = len(message) - candy_count - snowflake_count - k
		idx = 0
		while caracteres_a_remover > 0 and idx < len(message):
			if message[idx] in ['*', '?']:
				aux.add(idx - 1)
				caracteres_a_remover -= 1
			idx += 1
		for i in range(len(message)):
			if message[i] not in ['*', '?'] and i not in aux:
				ans += message[i]
		print(ans)
C()


wrong_ans = 'Impossible'
s = input()
k = int(input())
snows = 0
led = 0
for i in s:
	if i == '*':
		snows += 1
	elif i == '?':
		led += 1
n = len(s) - led - snows
if k > n:
	if snows == 0:
		print(wrong_ans)
		exit(0)
elif k < n:
	if n - k > snows + led:
		print(wrong_ans)
		exit()
dif = n - k
ans = ''
for i in s:
	if i == '*':
		if dif > 0:
			ans = ans[:-1]
			dif -= 1
		elif dif < 0:
			for c in range(-dif):
				ans += ans[-1]
			dif = 0
	elif i == '?':
		if dif > 0:
			ans = ans[:-1]
			dif -= 1
	else:
		ans += i
print(ans)


s = input().strip()
k = int(input())
l = 0
c = 0
an = ''
for v in s:
	if v != '?' and v != '*':
		c = c + 1
		an = an + v
	l = l + 1
if k > c and l - c > 0:
	l1 = k - c
	j = 0
	an = ''
	f = 0
	while j < l:
		if s[j] == '*':
			f = 1
			break
		elif s[j] != '?':
			an = an + s[j]
		j = j + 1
	if f == 1:
		an = an + s[j - 1] * l1
		for v in s[j + 1:]:
			if v != '*' and v != '?':
				an = an + v
	else:
		an = 'Impossible'
elif k < c and l - c >= c - k:
	l1 = c - k
	j = 0
	an = ''
	while l1 > 0:
		if s[j] == '?' or s[j] == '*':
			an = an[:-1]
			l1 = l1 - 1
		else:
			an = an + s[j]
		j = j + 1
	for v in s[j:]:
		if v != '*' and v != '?':
			an = an + v
elif k == c:
	f = 0
else:
	an = 'Impossible'
print(an)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	s = stdin.readline().rstrip('\n')
	n = int(stdin.readline())
	res = []
	lens = 0
	for c in s:
		if 'a' <= c and c <= 'z':
			lens = lens + 1
	i = len(s)
	while i > 0:
		i = i - 1
		c = s[i]
		if 'a' <= c and c <= 'z':
			res.append(c)
		if c == '?':
			if lens <= n:
				continue
			else:
				i = i - 1
				lens = lens - 1
				continue
		if c == '*':
			if lens <= n:
				while lens < n:
					lens = lens + 1
					res.append(s[i - 1])
				continue
			else:
				i = i - 1
				lens = lens - 1
				continue
	res.reverse()
	if len(res) != n:
		stdout.write('Impossible')
		return 0
	stdout.write(''.join([str(c) for c in res]))
	return 0
main()


__author__ = 'Sudip'
a = input()
l = int(input())
x = a.count('?')
y = a.count('*')
length = len(a) - x - y
poss = 1
if length - (x + y) > l:
	poss = 0
if y == 0 and l > length:
	poss = 0
if length > l and poss:
	for i in range(length - l):
		k = a.find('*')
		if k != -1:
			a = a.replace(a[k - 1] + a[k], '', 1)
		else:
			j = a.find('?')
			if j != -1:
				a = a.replace(a[j - 1] + a[j], '', 1)
elif length < l and poss:
	if poss:
		k = a.find('*')
		a = a.replace(a[k], a[k - 1] * (l - length), 1)
a = a.replace('*', '')
a = a.replace('?', '')
if poss:
	print(a)
else:
	print('Impossible')


s = list(input())
k = int(input())
n = len(s)
for i in range(len(s)):
	if s[i] == '?' or s[i] == '*':
		n -= 1
ans = []
if n == k:
	for i in range(len(s)):
		if s[i] != '?' and s[i] != '*':
			ans.append(s[i])
	print(''.join(ans))
elif n > k:
	for i in range(len(s) - 1):
		if (s[i + 1] == '?' or s[i + 1] == '*') and n > k:
			n -= 1
		elif s[i] != '?' and s[i] != '*':
			ans.append(s[i])
	if n == k:
		if s[len(s) - 1] == '?' or s[len(s) - 1] == '*':
			print(''.join(ans))
		else:
			ans.append(s[len(s) - 1])
			print(''.join(ans))
	else:
		print('Impossible')
else:
	count = 0
	for i in range(1, len(s)):
		if s[i] == '*':
			count += 1
	if count == 0:
		print('Impossible')
	else:
		if s[len(s) - 1] == '*' or s[len(s) - 1] == '?':
			k = k - 1
		else:
			k = k - 1
		for i in range(len(s) - 1):
			if s[i + 1] == '*':
				while n <= k:
					ans.append(s[i])
					n += 1
			if s[i] != '?' and s[i] != '*':
				ans.append(s[i])
		if s[len(s) - 1] == '*' or s[len(s) - 1] == '?':
			pass
		else:
			ans.append(s[len(s) - 1])
		print(''.join(ans))


s = input()
k = int(input())
a = []
b = []
n = 0
st = -1
for i in s:
	if i.isalpha():
		a.append(i)
		b.append(0)
	else:
		if len(b) > 0:
			if i == '?':
				b[-1] = 1
			if i == '*':
				st = len(b) - 1
				b[-1] = 2
		n += 1
if k < len(a) - n or (k > len(a) and st < 0):
	print('Impossible')
elif st >= 0:
	left = []
	right = []
	for i in range(len(a)):
		if b[i] == 0:
			if i < st:
				left.append(a[i])
			else:
				right.append(a[i])
	mid = [a[st]] * (k - len(left) - len(right))
	print(''.join(left + mid + right))
else:
	allow = k - len(a) + n
	l = []
	for i in range(len(a)):
		if b[i] == 0:
			l.append(a[i])
		elif allow > 0:
			l.append(a[i])
			allow -= 1
	print(''.join(l))


word = list(map(str, input()))
k = int(input())
alpha = 0
can = 0
snow = 0
for i in range(len(word)):
	if word[i] == '?':
		can += 1
	elif word[i] == '*':
		snow += 1
	else:
		alpha += 1
if alpha == k:
	ans = ''
	for i in word:
		if i != '?' and i != '*':
			ans += i
	print(ans)
elif alpha < k:
	if snow == 0:
		print('Impossible')
	else:
		ans = ''
		diff = k - alpha
		for i in range(len(word)):
			if word[i] == '?':
				pass
			elif word[i] == '*':
				ans += word[i - 1] * diff
				diff = 0
			else:
				ans += word[i]
		print(ans)
else:
	diff = alpha - k
	if diff > snow + can:
		print('Impossible')
	else:
		ans = ''
		vis = [False for i in range(len(word))]
		diff = alpha - k
		for i in range(len(word)):
			if word[i] in ['?', '*']:
				if diff != 0:
					vis[i - 1] = True
					diff -= 1
		for i in range(len(word)):
			if word[i] not in ['?', '*'] and vis[i] == False:
				ans += word[i]
		print(ans)


string = list(input())
ques = 0
stars = 0
n = len(string)
k = int(input())
for s in string:
	if s == '?':
		ques += 1
	elif s == '*':
		stars += 1
	else:
		continue
org = n - stars - ques
if org - stars - ques > k:
	print('Impossible')
elif org < k and stars != 0:
	ex = k - org
	final = []
	done = False
	for i in range(0, n):
		if string[i] == '?':
			pass
		elif string[i] == '*' and done:
			pass
		elif string[i] == '*':
			done = True
			final.extend([string[i - 1]] * ex)
		else:
			final.append(string[i])
	print(''.join(final))
elif org < k and stars == 0:
	print('Impossible')
elif org >= k:
	to_remove = org - k
	final = []
	cnt = 0
	for i in range(0, n):
		if string[i] in ('?', '*'):
			if cnt == to_remove:
				pass
			else:
				cnt += 1
				final.pop(-1)
		else:
			final.append(string[i])
	print(''.join(final))


s = input()
n = int(input())
cur = len(s) - 2 * (s.count('?') + s.count('*'))
if cur <= n:
	ans = []
	if '*' in s:
		flag = True
		for i in range(0, len(s) - 1):
			if s[i + 1] == '*' and flag:
				flag = False
				while cur < n:
					cur += 1
					ans.append(s[i])
			elif s[i + 1] == '*' or s[i + 1] == '?' or s[i] == '*' or (s[i] == '?'):
				pass
			else:
				ans.append(s[i])
		if s[-1] != '?' and s[-1] != '*':
			ans.append(s[-1])
		print(''.join(ans))
	else:
		if len(s) - s.count('?') < n:
			print('Impossible')
			exit()
		for i in range(0, len(s) - 1):
			if s[i] == '?':
				continue
			if not (s[i + 1] == '?' and cur >= n):
				ans.append(s[i])
				if s[i + 1] == '?':
					cur += 1
		if s[-1] != '?':
			ans.append(s[-1])
		print(''.join(ans))
else:
	print('Impossible')