fork download
  1. t = int(input())
  2. for i in range(t):
  3. a = input()
  4. s = input()
  5. list_a = []
  6. sum = 0
  7. for i in range(len(s)):
  8. for j in range(len(a)):
  9. if s[i] == a[j]:
  10. k = len(a[:j])
  11. list_a.append(k)
  12. for i in range(1, len(list_a)):
  13. sum = sum + abs((list_a[i] - list_a[i-1]))
  14. print(sum)
Success #stdin #stdout 0.03s 9684KB
stdin
5
abcdefghijklmnopqrstuvwxyz
hello
abcdefghijklmnopqrstuvwxyz
i
abcdefghijklmnopqrstuvwxyz
codeforces
qwertyuiopasdfghjklzxcvbnm
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
qwertyuiopasdfghjklzxcvbnm
abacaba
stdout
13
0
68
0
74