description: You are given a keyboard that consists of 26 keys. The keys are arranged sequentially in one row in a certain order. Each key corresponds to a unique lowercase Latin letter.
  
  You have to type the word s on this keyboard. It also consists only of lowercase Latin letters.
  
  To type a word, you need to type all its letters consecutively one by one. To type each letter you must position your hand exactly over the corresponding key and press it.
  
  Moving the hand between the keys takes time which is equal to the absolute value of the difference between positions of these keys (the keys are numbered from left to right). No time is spent on pressing the keys and on placing your hand over the first letter of the word.
  
  For example, consider a keyboard where the letters from 'a' to 'z' are arranged in consecutive alphabetical order. The letters 'h', 'e', 'l' and 'o' then are on the positions 8, 5, 12 and 15, respectively. Therefore, it will take |5 - 8| + |12 - 5| + |12 - 12| + |15 - 12| = 13 units of time to type the word "hello". 
  
  Determine how long it will take to print the word s.
  
  Input
  
  The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.
  
  The next 2t lines contain descriptions of the test cases.
  
  The first line of a description contains a keyboard — a string of length 26, which consists only of lowercase Latin letters. Each of the letters from 'a' to 'z' appears exactly once on the keyboard.
  
  The second line of the description contains the word s. The word has a length from 1 to 50 letters inclusive and consists of lowercase Latin letters.
  
  Output
  
  Print t lines, each line containing the answer to the corresponding test case. The answer to the test case is the minimal time it takes to type the word s on the given keyboard.
  
  Example
  
  Input
  
  
  5
  abcdefghijklmnopqrstuvwxyz
  hello
  abcdefghijklmnopqrstuvwxyz
  i
  abcdefghijklmnopqrstuvwxyz
  codeforces
  qwertyuiopasdfghjklzxcvbnm
  qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
  qwertyuiopasdfghjklzxcvbnm
  abacaba
  
  
  Output
  
  
  13
  0
  68
  0
  74
solution: 
  import java.io.*;
  import java.util.*;
  public class cp
  {
  	static class Reader {
  		final private int BUFFER_SIZE = 1 << 16;
  		private DataInputStream din;
  		private byte[] buffer;
  		private int bufferPointer, bytesRead;
  
  		public Reader()
  		{
  			din = new DataInputStream(System.in);
  			buffer = new byte[BUFFER_SIZE];
  			bufferPointer = bytesRead = 0;
  		}
  
  		public Reader(String file_name) throws IOException
  		{
  			din = new DataInputStream(
  					new FileInputStream(file_name));
  			buffer = new byte[BUFFER_SIZE];
  			bufferPointer = bytesRead = 0;
  		}
  
  		public String readLine() throws IOException
  		{
  			byte[] buf = new byte[64]; // line length
  			int cnt = 0, c;
  			while ((c = read()) != -1) {
  				if (c == '\n') {
  					if (cnt != 0) {
  						break;
  					}
  					else {
  						continue;
  					}
  				}
  				buf[cnt++] = (byte)c;
  			}
  			return new String(buf, 0, cnt);
  		}
  
  		public int nextInt() throws IOException
  		{
  			int ret = 0;
  			byte c = read();
  			while (c <= ' ') {
  				c = read();
  			}
  			boolean neg = (c == '-');
  			if (neg)
  				c = read();
  			do {
  				ret = ret * 10 + c - '0';
  			} while ((c = read()) >= '0' && c <= '9');
  
  			if (neg)
  				return -ret;
  			return ret;
  		}
  
  		public long nextLong() throws IOException
  		{
  			long ret = 0;
  			byte c = read();
  			while (c <= ' ')
  				c = read();
  			boolean neg = (c == '-');
  			if (neg)
  				c = read();
  			do {
  				ret = ret * 10 + c - '0';
  			} while ((c = read()) >= '0' && c <= '9');
  			if (neg)
  				return -ret;
  			return ret;
  		}
  
  		public double nextDouble() throws IOException
  		{
  			double ret = 0, div = 1;
  			byte c = read();
  			while (c <= ' ')
  				c = read();
  			boolean neg = (c == '-');
  			if (neg)
  				c = read();
  
  			do {
  				ret = ret * 10 + c - '0';
  			} while ((c = read()) >= '0' && c <= '9');
  
  			if (c == '.') {
  				while ((c = read()) >= '0' && c <= '9') {
  					ret += (c - '0') / (div *= 10);
  				}
  			}
  
  			if (neg)
  				return -ret;
  			return ret;
  		}
  
  		private void fillBuffer() throws IOException
  		{
  			bytesRead = din.read(buffer, bufferPointer = 0,
  					BUFFER_SIZE);
  			if (bytesRead == -1)
  				buffer[0] = -1;
  		}
  
  		private byte read() throws IOException
  		{
  			if (bufferPointer == bytesRead)
  				fillBuffer();
  			return buffer[bufferPointer++];
  		}
  
  		public void close() throws IOException
  		{
  			if (din == null)
  				return;
  			din.close();
  		}
  	}
  
  	/* Iterative Function to calculate (x^y) in O(log y) */
  	static long power(long x, long y, long p)
  	{
  		long res = 1; // Initialize result
  
  		x = x % p; // Update x if it is more than or
  		// equal to p
  
  		if (x == 0)
  			return 0; // In case x is divisible by p;
  
  		while (y > 0)
  		{
  
  			// If y is odd, multiply x with result
  			if ((y & 1) != 0)
  				res = (res * x) % p;
  
  			// y must be even now
  			y = y >> 1; // y = y/2
  			x = (x * x) % p;
  		}
  		return res;
  	}
  
  	static int power(int x,int y) {
  		if(y == 0) {
  			return 1;
  		}
  		if(y % 2 == 0) {
  			int temp = power(x,y/2)%1000000007;
  			return temp*temp%1000000007;
  
  		}else {
  			return ((x%1000000007)*power(x,y-1))%1000000007;
  		}
  
  	}
  
  	static long getPairsCount(int n, long sum,long arr[])
  	{
  		HashMap<Long, Integer> hm = new HashMap<>();
  
  		// Store counts of all elements in map hm
  		for (int i = 0; i < n; i++) {
  
  			// initializing value to 0, if key not found
  			if (!hm.containsKey(arr[i]))
  				hm.put(arr[i], 0);
  
  			hm.put(arr[i], hm.get(arr[i]) + 1);
  		}
  		long twice_count = 0;
  
  		// iterate through each element and increment the
  		// count (Notice that every pair is counted twice)
  		for (int i = 0; i < n; i++) {
  			if (hm.get(sum - arr[i]) != null)
  				twice_count += hm.get(sum - arr[i]);
  
  			// if (arr[i], arr[i]) pair satisfies the
  			// condition, then we need to ensure that the
  			// count is decreased by one such that the
  			// (arr[i], arr[i]) pair is not considered
  			if (sum - arr[i] == arr[i])
  				twice_count--;
  		}
  
  		// return the half of twice_count
  		return twice_count / 2;
  	}
  
  	public static long check(int index,String str) {
  		long count = 0;
  		for(int i = 1;i <= 9 && index + i < str.length();i++) {
  			if( Math.abs(str.charAt(index + i) - str.charAt(index)) == i) {
  				count++;
  			}
  		}
  		return count;
  	}
  
  	public static  long[] primeFactors(long n)
  	{
  		// Print the number of 2s that divide n
  		//		Vector<Integer> v = new Vector<>();
  		long countEve = 0;
  		long countOdd = 0;
  		while (n%2==0)
  		{
  			//            v.add(2);
  			countEve++;
  			n /= 2;
  		}
  
  		// n must be odd at this point.  So we can
  		// skip one element (Note i = i +2)
  		for (int i = 3; i <= Math.sqrt(n); i+= 2)
  		{
  			// While i divides n, print i and divide n
  			while (n%i == 0)
  			{
  				countOdd++;
  				n /= i;
  			}
  		}
  
  		// This condition is to handle the case when
  		// n is a prime number greater than 2
  		if (n > 2)
  			countOdd++;
  
  		long ans[] = {countEve,countOdd};
  		return ans;
  
  	}
  
  	public static HashMap<Integer, Integer>
  	sortByValue(HashMap<Integer, Integer> hm)
  	{
  		// Create a list from elements of HashMap
  		List<Map.Entry<Integer, Integer> > list
  		= new LinkedList<Map.Entry<Integer, Integer> >(
  				hm.entrySet());
  
  		// Sort the list using lambda expression
  		Collections.sort(
  				list,
  				(i1,
  						i2) -> i1.getValue().compareTo(i2.getValue()));
  
  		// put data from sorted list to hashmap
  		HashMap<Integer, Integer> temp
  		= new LinkedHashMap<Integer, Integer>();
  		for (Map.Entry<Integer, Integer> aa : list) {
  			temp.put(aa.getKey(), aa.getValue());
  		}
  		return temp;
  	}
  
  
  	public static void main(String[] args) throws IOException
  	{	
  
  		try{
  			//Your Solve
  //			Reader s = new Reader();
  
  			Scanner s = new Scanner(System.in);
  
  			int t = s.nextInt();
  			for(int p = 0;p < t;p++) {
  				String str = s.next();
  				String find = s.next();
  				
  				int arr[] = new int[26];
  				for(int i = 0;i < str.length();i++) {
  					arr[str.charAt(i)-'a'] = i;
  
  				}
  				
  //				if(find.length() == 1) {
  //					System.out.println(0);
  //				}else {
  					int count = 0;
  					for(int i = 1;i < find.length();i++) {
  						count += Math.abs(arr[find.charAt(i)-'a'] - arr[find.charAt(i-1)-'a']);
  					}
  //				}
  				System.out.println(count);
  
  			}
  
  		}catch(Exception e){
  			return;
  		}
  	}
  }