Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup!

Actually, Polycarp has already came up with the name but some improvement to it will never hurt. So now he wants to swap letters at some positions in it to obtain the better name. It isn't necessary for letters to be adjacent.

In addition, each of the investors has chosen some index in the name and selected a set of letters that can go there. Indices chosen by different investors are pairwise distinct. If some indices aren't chosen by any investor then any letter can go there.

Finally, Polycarp is sure that the smallest lexicographically name is the best. (Like why do you think Google decided to become Alphabet?)

More formally, you are given a string consisting of lowercase Latin letters from "a" to "f". You can swap letters at any positions arbitrary number of times (zero swaps is also possible).

What is the smallest lexicographically name you can obtain such that the letter at every position is among the allowed letters?

If Polycarp can't produce any valid name then print "Impossible".
The first line is the string $s$ ($1 \le |s| \le 10^5$) — the name Polycarp has came up with. The string consists only of lowercase Latin letters from "a" to "f".

The second line contains a single integer $m$ ($0 \le m \le |s|$) — the number of investors.

The $i$-th of the next $m$ lines contain an integer number $pos_i$ and a non-empty string of allowed characters for $pos_i$ ($1 \le pos_i \le |s|$). Each string contains pairwise distinct letters from "a" to "f". $pos_1, pos_2, \dots, pos_m$ are pairwise distinct. If any position of the string doesn't appear in the investors demands then any letter can go in this position.
bedefead
5
2 e
1 dc
5 b
7 ef
6 ef
deadbeef
abacaba
0
aaaabbc
fc
2
1 cfab
2 f
cf
bbcbbc
6
1 c
2 c
3 b
4 ab
5 ab
6 ab
ccbbbb
abcdefffffffffffffff
5
20 abcde
19 abcde
18 abcde
17 abcde
16 abcde
fffffffffffffffabcde
abcdefffffffffffffff
20
1 acf
2 cdef
3 ef
4 def
5 adef
6 acdef
7 bdef
8 abdf
9 bcdf
10 abf
11 abf
12 bcdf
13 df
14 df
15 abcdf
16 abcde
17 abcde
18 abcde
19 abcde
20 abcde
fffffffffffffffabcde
aaeff
5
2 afbdce
5 c
1 dbc
4 afcbde
3 ef
Impossible
cdff
1
2 ae
Impossible
dfb
2
1 c
3 cae
Impossible
cefe
2
4 ca
1 da
Impossible
cdccc
5
2 fae
1 dabc
4 dcfabe
3 abc
5 bdcafe
Impossible
bdc
3
1 f
3 fdacb
2 eb
Impossible
effa
3
3 ca
2 bd
4 abfdce
Impossible
bfd
2
2 aecf
3 dfb
bfd
bfb
3
1 f
3 acdef
2 cdefab
Impossible
fce
3
3 abdecf
1 efdcba
2 ac
ecf
ded
1
2 aedc
dde
a
1
1 b
Impossible
#!/usr/bin/python3

INF = 10 ** 10


def dfs(N, G, F, dest, i, visited, flow):
    visited.add(i)

    if i == dest:
        return flow

    for j in range(N):
        if j in visited or G[i][j] - F[i][j] - G[j][i] + F[j][i] <= 0:
            continue

        this_f = min(flow, G[i][j] - F[i][j] - G[j][i] + F[j][i])
        f = dfs(N, G, F, dest, j, visited, this_f)
        if f > 0:
            F[i][j] += f
            visited.remove(i)
            return f

    visited.remove(i)
    return 0


def maxflow(N, G, F, src, dest):
    flow = 0
    while True:
        f = dfs(N, G, F, dest, src, set(), INF)
        if f == 0:
            break
        flow += f

    return flow


def solve(S, M, A):
    masks = [63] * len(S)
    for i, chars in A:
        mask = 0
        for c in chars:
            mask |= 1 << (ord(c) - ord('a'))
        masks[i] = mask

    maskcnt = [0] * 64
    for m in masks:
        maskcnt[m] += 1

    charcnt = [0] * 6
    for c in S:
        charcnt[ord(c) - ord('a')] += 1

    SOURCE = 0
    SINK = 1
    MASKS = 2
    CHARS = MASKS + 64
    N = CHARS + 6

    G = [[0] * N for _ in range(N)]

    for i in range(64):
        G[SOURCE][MASKS + i] = maskcnt[i]

    for i in range(6):
        G[CHARS + i][SINK] = charcnt[i]

    for m in range(64):
        for i in range(6):
            if m & (1 << i):
                G[MASKS + m][CHARS + i] = INF

    F = [[0] * N for _ in range(N)]
    flow = maxflow(N, G, F, SOURCE, SINK)
    if flow < len(S):
        return None

    ans = []
    k = len(S)
    for i in range(len(S)):
        m = masks[i]
        for c in range(6):
            if not (m & (1 << c)) or G[CHARS + c][SINK] == 0:
                continue
            G[SOURCE][MASKS + m] -= 1
            G[CHARS + c][SINK] -= 1
            k -= 1

            F = [[0] * N for _ in range(N)]
            flow = maxflow(N, G, F, SOURCE, SINK)

            if flow == k:
                ans.append(chr(ord('a') + c))
                break

            G[SOURCE][MASKS + m] += 1
            G[CHARS + c][SINK] += 1
            k += 1

    assert len(ans) == len(S)
    return ''.join(ans)


def main():
    S = input()
    M = int(input())
    A = []
    for _ in range(M):
        ps, chars = input().split(' ')
        p = int(ps)
        p -= 1
        A.append((p, chars))

    res = solve(S, M, A)
    if res is None:
        print('Impossible')
    else:
        print(res)


if __name__ == '__main__':
    main()
