Comments

Inside of your solve function, these lines are technically O(n^2) since string concatenation is O(n) in python.

    ans = ""
    for i in s:
        ans += dic[i]
    print(ans) 

However, the compiler that python3 uses optimizes it to O(n) but pypy3's doesn't. I would recommend just adding each character to a list and joining them at the end with .join().