from itertools import permutations MOD = 998244353 N = int(input()) A = list(map(int, input().split())) B = [] for i in range(N): sA = str(A[i]) S = [] for j in range(20): if len(sA) <= j: S.append(S[-1]) else: S.append(sA[j]) B.append(("".join(S), i)) B.sort() x = 0 for i in range(N): idx = B[i][1] x = pow(10, len(str(A[idx]))) * x + A[idx] x %= MOD print(x) # print(B)