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: #include <bits/stdc++.h>
  using namespace std;
  using ll = long long;
  using ld = double;
  using pi = pair<int, int>;
  using pl = pair<ll, ll>;
  using pd = pair<ld, ld>;
  using cd = complex<ld>;
  using vcd = vector<cd>;
  using vi = vector<int>;
  using vl = vector<ll>;
  using vd = vector<ld>;
  using vs = vector<string>;
  using vpi = vector<pi>;
  using vpl = vector<pl>;
  using vpd = vector<pd>;
  template <class T>
  using min_pq = priority_queue<T, vector<T>, greater<T> >;
  template <class T>
  inline int ckmin(T& a, const T& val) {
    return val < a ? a = val, 1 : 0;
  }
  template <class T>
  inline int ckmax(T& a, const T& val) {
    return a < val ? a = val, 1 : 0;
  }
  template <class T>
  void remDup(vector<T>& v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), end(v));
  }
  constexpr int pct(int x) { return __builtin_popcount(x); }
  constexpr int bits(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }
  constexpr int p2(int x) { return 1 << x; }
  constexpr int msk2(int x) { return p2(x) - 1; }
  ll ceilDiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
  ll floorDiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
  void setPrec(int x) { cout << fixed << setprecision(x); }
  string to_string(char c) { return string(1, c); }
  string to_string(const char* s) { return (string)s; }
  string to_string(string s) { return s; }
  string to_string(bool b) { return to_string((int)b); }
  template <class T>
  string to_string(complex<T> c) {
    stringstream ss;
    ss << c;
    return ss.str();
  }
  template <class T>
  using V = vector<T>;
  string to_string(V<bool> v) {
    string res = "{";
    for (int i = (0); i <= (int((v).size()) - 1); i++) res += char('0' + v[i]);
    res += "}";
    return res;
  }
  template <size_t sz>
  string to_string(bitset<sz> b) {
    string res = "";
    for (int i = (0); i <= (int((b).size()) - 1); i++) res += char('0' + b[i]);
    return res;
  }
  template <class T, class U>
  string to_string(pair<T, U> p);
  template <class T>
  string to_string(T v) {
    bool fst = 1;
    string res = "";
    for (const auto& x : v) {
      if (!fst) res += " ";
      fst = 0;
      res += to_string(x);
    }
    return res;
  }
  template <class T, class U>
  string to_string(pair<T, U> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
  }
  template <class T>
  void pr(T x) {
    cout << to_string(x);
  }
  template <class T, class... U>
  void pr(const T& t, const U&... u) {
    pr(t);
    pr(u...);
  }
  void ps() { pr("\n"); }
  template <class T, class... U>
  void ps(const T& t, const U&... u) {
    pr(t);
    if (sizeof...(u)) pr(" ");
    ps(u...);
  }
  void DBG() { cerr << "]" << endl; }
  template <class T, class... U>
  void DBG(const T& t, const U&... u) {
    cerr << to_string(t);
    if (sizeof...(u)) cerr << ", ";
    DBG(u...);
  }
  const ld PI = acos(-1.0);
  const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  const ld EPS = 1e-9;
  const ll MODBASE = 1000000007LL;
  const int INF = 0x3f3f3f3f;
  const int MAXN = 110;
  const int MAXM = 1000;
  const int MAXK = 16;
  const int MAXQ = 200010;
  int f[26];
  int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int te;
    cin >> te;
    while (te--) {
      string s, t;
      cin >> s >> t;
      for (int i = (0); i <= (25); i++) f[s[i] - 'a'] = i;
      int res = 0;
      for (int i = (1); i <= (int((t).size()) - 1); i++) {
        res += abs(f[t[i] - 'a'] - f[t[i - 1] - 'a']);
      }
      cout << res << "\n";
    }
    return 0;
  }
  