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$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 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.

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.

5
abcdefghijklmnopqrstuvwxyz
hello
abcdefghijklmnopqrstuvwxyz
i
abcdefghijklmnopqrstuvwxyz
codeforces
qwertyuiopasdfghjklzxcvbnm
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
qwertyuiopasdfghjklzxcvbnm
abacaba

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var a = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            a = lines[i].split('');
        }else{
            var b = lines[i].split('');
            var v = new Map();
            for(j = 0; j < a.length; j++){
                v.set(a[j], j);
            }
            var ans = 0;
            for(j = 1; j < b.length; j++){
                var x = v.get(b[j]);
                var y = v.get(b[j - 1]);
                ans += Math.abs(x - y);
            }
            console.log(ans);
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    var a = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i].split('');
            a = new Map();
            for(j = 1; j <= n.length; j++){
                a.set(n[j - 1], j);
            }
        }else{
            var k = lines[i].split('');
            var ans = 0;
            var x = 0, y = 0;
            for(j = 1; j < k.length; j++){
                x = a.get(k[j]);
                y = a.get(k[j - 1]);
                ans += Math.abs(x - y);
            }
            console.log(ans);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var a = new Map();
    for(var j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            a = new Map();
            var keyboard = lines[j];
            for(var l = 1; l < 27; l++){
                a.set(keyboard[l - 1], l);
            }
        }else{
            var word = lines[j];
            var answer = 0;
            var b = 0;
            var c = 0;
            for(var h = 1; h < word.length; h++){
                b = a.get(word[h]);
                c = a.get(word[h - 1]);
                answer += Math.abs(b - c);
            }
            console.log(answer);
        }
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    run(...inputString);
});

function readline() {
    return inputString[currentLine++];
}

const input = readline();

function run(...args) {

  const findDistance = (keyboard, word) => {
    const keyboardMap = {};
    for (let i = 0; i <= keyboard.length; i++) {
      if (!keyboardMap[keyboard[i]]) {
        keyboardMap[keyboard[i]] = i + 1;
      }
    }

    let sum = 0;
    for (let i = 0; i < word.length - 1; i++) {
      let firstValue = keyboardMap[word[i]];
      let secondValue = keyboardMap[word[i + 1]];

      if (firstValue > secondValue) {
        sum += firstValue - secondValue;
      } else {
        sum += secondValue - firstValue;
      }
    }
    return sum;
  };

  for (let i = 1; i < args.length - 1; i+=2) {
    const r = findDistance(args[i], args[i + 1]);
    console.log(r)

  }

}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var a = new Map();
    for(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            a = new Map();
            var keyboard = lines[j];
            for(l = 1; l < 27; l++){
                a.set(keyboard[l - 1], l);
            }
        }else{
            var word = lines[j];
            var answer = 0;
            var b = 0;
            var c = 0;
            for(h = 1; h < word.length; h++){
                b = a.get(word[h]);
                c = a.get(word[h - 1]);
                answer += Math.abs(b - c);
            }
            console.log(answer);
        }
    }
});

"use strict";
exports.__esModule = true;
var readline = require("readline");
var process = require("process");
var console_1 = require("console");
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
var lines = [];
rl.on("line", function (line) {
    lines.push(line);
});
rl.on("close", function () {
    main();
});
function main() {
    for (var i = 1; i < lines.length; i += 2) {
        var time = solve(lines[i], lines[i + 1]);
        console.log(time);
    }
}
function range(start, length) {
    (0, console_1.assert)(length > 0);
    return Array.from(Array(length).keys()).map(function (x) { return x + start; });
}
function solve(keyboard, word) {
    if (word.length <= 1) {
        return 0;
    }
    var keys = Array.from(keyboard);
    var keyIndexes = range(0, keyboard.length);
    var keyMap = new Map(keyIndexes.map(function (i) { return [keys[i], i]; }));
    var wordIndexes = Array.from(word).map(function (c) { return keyMap.get(c); });
    var distances = range(0, word.length - 1).map(function (i) {
        return Math.abs(wordIndexes[i] - wordIndexes[i + 1]);
    });
    var time = distances.reduce(function (x, y) { return x + y; }, 0);
    return time;
}

var readline = require("readline");

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

var lines = [];

rl.on("line", function (line) {
  lines.push(line);
});

rl.on("close", function () {
  for (let i = 1; i < lines.length; i += 2) {
    let time = solve(lines[i], lines[i + 1]);
    console.log(time);
  }
});

function solve(keyboard, s) {
  if (s.length <= 1) {
    return 0;
  }

  let keyboardMap = new Map();
  for (let i = 0; i < keyboard.length; i++) {
    keyboardMap.set(keyboard[i], i);
  }

  letterPositions = [];

  for (let i = 0; i < s.length; i++) {
    letterPositions.push(keyboardMap.get(s[i]));
  }

  let time = 0;
  let handPosition = letterPositions[0];

  for (let i = 1; i < s.length; i++) {
    time += Math.abs(letterPositions[i] - handPosition);
    handPosition = letterPositions[i];
  }

  return time;
}

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let c = 0;
let alpha;

rl.on("line", (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (c % 2 === 1) {
    alpha = d;
    c++;
    return;
  }

  let ans = 0;
  const idxes = [];
  const word = d;

  for (let i = 0; i < word.length; i++) {
    const idx = alpha.indexOf(word[i]);
    idxes.push(idx);
  }

  for (let i = 1; i < idxes.length; i++) {
    ans += Math.abs(idxes[i - 1] - idxes[i]);
  }

  console.log(ans);
  c++;
});

rl.on("close", () => {});

// cls; cat .\input.txt | node .\script.js
// codium --diff file1.js file2.js
'use strict';
let data = ''; // raw
let inputs = ''; // iterator
function read() { return inputs.next().value.trim(); };

async function solve() {
    let t_1 = (await read()).split('')
    let t_2 = (await read()).split('')
    let keyMap = new Map(t_1.map((e, i) =>
        [e, i + 1]
    ))
    let reduced = t_2.reduce((a, e, i, o) => {
        if (i == 0) return a
        let current = keyMap.get(o[i])
        let previous = keyMap.get(o[i - 1])
        let diff = Math.abs(current - previous)
        return a + diff
    }, 0)
    console.log(reduced)
}

async function main() {
    let tasks_amount = parseInt(await read())
    for (let i = 0; i < tasks_amount; i++) {
        await solve()
    }
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => data += input);
process.stdin.on('end', async () => {
    let splitted = data.split('\r\n')
    inputs = await splitted.values();
    await main();
});

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let j = 0; j < t; j++){
		let a = nl.line().split('');
		let b = nl.line().split('');
		let al = {};
		a.forEach((e, i) => al[e] = i);
		let cnt = 0;
		for(let i = 1; i < b.length; i++) {
			cnt += Math.abs(al[b[i]] - al[b[i-1]]);
		}
		ans.push(cnt);
	}
	console.log(ans.join('\n'));
};

process.stdin.on('end', sol);

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const k = rl();
		const s = rl();

		let ans = 0;
		for (let i = 1; i < s.length; i++) {
			ans += Math.abs(k.indexOf(s[i]) - k.indexOf(s[i-1]));
		}

		console.log(ans);
	}
}

/*
** 1607a Linear Keyboard
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

// LIBRARY START //

const isOdd = (x) => { return x & 1 }
const isEven = (x) => { return !(x & 1) }

const reverseText = (s) => { return s.split('').reverse().join('') }
const hasDuplicates = (str) => (/([a-z])\1/i).test(str)

const hasDuplicateChar = (str, char) => str.indexOf(char) !== str.lastIndexOf(char)

const isSorted = arr => arr.every((v, i, a) => !i || a[i - 1] <= v);

const findAllIndicesOfChar = (str, char) => {
    str = str.split('')
    let indices = [];
    for (let i = 0; i < str.length; i++) {
        if (str[i] === char) indices.push(i);
    }
    return indices
}

const splitAt = index => x => [x.slice(0, index), x.slice(index)]

const isUpper = str => !/[a-z]/.test(str) && /[A-Z]/.test(str)

const escapeRegExp = (string) => string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&')

const replaceAll = (str, find, replace) => str.replace(new RegExp(escapeRegExp(find), 'g'), replace)

const findUnique = (str) => {
    return [...str].reduce((acc, curr) => {
        return acc.includes(curr) ? acc : acc + curr;
    }, "")
}

// LIBRARY END

const tempPrintFunc = (keyboard, word) => {
    keyboard = keyboard.split('')
    word = word.split('')

    let val = 0
    let currChar = word[0]

    while (word.length > 0) {
        nextChar = word.shift()

        curr_pos = keyboard.indexOf(currChar)
        next_pos = keyboard.indexOf(nextChar)

        val += Math.abs(curr_pos - next_pos)

        currChar = nextChar
    }

    return val
}

//*
function main() {
    let cases = readline()

    while (cases--) {
        let keyboard = readline()
        let word = readline()
        console.log(tempPrintFunc(keyboard, word))
    }
}
//*/

// let keyboard = ''
// let word = ''

// keyboard = 'abcdefghijklmnopqrstuvwxyz'
// word = 'hello'
// console.log(tempPrintFunc(keyboard, word) == 13)

// keyboard = 'abcdefghijklmnopqrstuvwxyz'
// word = 'i'
// console.log(tempPrintFunc(keyboard, word) == 0)

// keyboard = 'abcdefghijklmnopqrstuvwxyz'
// word = 'codeforces'
// console.log(tempPrintFunc(keyboard, word) == 68)

// keyboard = 'qwertyuiopasdfghjklzxcvbnm'
// word = 'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq'
// console.log(tempPrintFunc(keyboard, word) == 0)

// keyboard = 'qwertyuiopasdfghjklzxcvbnm'
// word = 'abacaba'
// console.log(tempPrintFunc(keyboard, word) == 74)

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let t = Number(readline())
    for (let j = 1; j <= t; j++) {
        let s=readline();
        let n=s.length;
        let x=readline();
        let ans=0;
        let mp=new Map();
        for(let i=0;i<n;i++)
            mp[s[i]]=i;
        let m=x.length;
        for(let i=1;i<m;i++)
            ans+=Math.abs(mp[x[i]]-mp[x[i-1]]);
        console.log(ans);
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

function main(){
  let input = Number(readline());
  let output = [];
  for(let i=0; i<input; i++){
    let pattern = readline().replace('\r','');
    let word = readline().replace('\r', '');
    if(word.length===1) output.push('0');
    else output.push(minimalTime(pattern, word))
  }
  for(let j=0; j<output.length; j++){
    print(output[j])
  }
}

function minimalTime(pattern, word){
  let time = 0;
  for(let i=1; i<=(word.length-1); i++){
    time += Math.abs(((pattern.indexOf(word[i-1])+1) - (pattern.indexOf(word[i])+1)));
    }

  return time;
}

function findSum (input, alphabetIndex, wordIndex) {
  const alphabet = input[alphabetIndex];
  const word = input[wordIndex];
  if (word.length === 1) return 0;
  const map = new Map();
  let sum = 0;
  for (let i = 0; i < alphabet.length; i++)
  {
        map.set(alphabet[i], i + 1);
  }
  for (let i = 1; i < word.length; i++)
  {
    sum += Math.abs(map.get(word[i - 1]) - map.get(word[i]));
  }
  return sum;
}

let i = "";
process.stdin.on("data", (c) => (i += c));
process.stdin.on("end", () => {
  const { EOL } = require("os");
  const input = i.split(EOL);
  const n = input[0];
  let alphabetIndex = 1;
  let wordIndex = 2;
  for (let i = 0; i < n; i++) {
      console.log(findSum (input, alphabetIndex, wordIndex));
      alphabetIndex += 2;
      wordIndex += 2;
  }

})

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
        if (count === -1) {
            count = +data * 2
        } else if (count !== 0) {
            inputArr.push(data.trim())
            count--
        }
        // max number 2^(53) - 1 ~~ 10^(15)
        if (count === 0) {
            main()
            process.exit(0)
        }
    }
)

function solve(keyboard, str) {
    str = str.split('')
    let res = 0
    for (let i = 0; i < str.length - 1; ++i) {
        res += Math.abs((keyboard.indexOf(str[i]) + 1) - (keyboard.indexOf(str[i + 1]) + 1))
    }
    console.log(res)
}

function main() {
    for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function gcd(a, b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// let a=readline().split(' ').map(Number)
// a.sort((a,b)=>a-b)

function main() {
    let t = Number(readline())
    for (let j = 1; j <= t; j++) {
        let s=readline();
        let n=s.length;
        let x=readline();
        let ans=0;
        let mp=new Map();
        for(let i=0;i<n;i++)
            mp[s[i]]=i;
        let m=x.length;
        for(let i=1;i<m;i++)
            ans+=Math.abs(mp[x[i]]-mp[x[i-1]]);
        console.log(ans);
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var c = next();
		var s = next();
		var output = 0;
		var index = c.indexOf(s[0]);
		for(var i = 1; i < s.length; i++){
			output += Math.abs(index - c.indexOf(s[i]));
			index = c.indexOf(s[i]);
		}
		myout(output);
	}
}

var t = readline();
for (var i=0 ; i < t ; i++){
    var keyboard = readline().split(''),
        word = readline().split(''),
        counter =0;
        for(var j = 0 ; j < word.length-1; j++){
            counter+= Math.abs(parseInt(keyboard.indexOf(word[j+1])) - parseInt(keyboard.indexOf(word[j])));
        }
        print(counter);
}

var testCase = +readline(),counter
for(var i=0;i<testCase;i++){
    var counter=0
    var sequence=readline()
    var test=readline()
    for(var j=0;j<test.length;j++){
            if(j!==0){
                counter=counter+Math.abs((sequence.indexOf(test[j])+1)-(sequence.indexOf(test[j-1])+1))
            }
    }
    print(counter)
}

function getObj(str) {
	var o={};
	for (var i = 0; i < str.length; i++) {
		o[str[i]]=i;
	}
	return o;
}

function ans(str,str2) {
	var hm=getObj(str2);
	var sum=0;
	for (var i = 1; i < str.length; i++) {
		var temp= hm[str[i]]-hm[str[i-1]];
		if(temp<0){
			temp=temp*-1;
		}
		sum+=temp;
	}
	return sum;
}

var a =readline();
for(var i=0;i<a;i++){
    var p=readline();
    var q=readline();
    print(ans(q,p));
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    var a = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i].split('');
            a = new Map();
            for(j = 1; j <= n.length; j++){
                a.set(n[j - 1], j);
            }
        }else{
            var k = lines[i].split('');
            var ans = 0;
            var x = 0, y = 0;
            for(j = 1; j < k.length; j++){
                x = a.get(k[j]);
                y = a.get(k[j - 1]);
                ans += Math.floor(x - y);
            }
            console.log(ans);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var a = new Map();
    for(var j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            a = new Map();
            var keyboard = lines[j];
            for(var l = 1; l < 27; l++){
                a.set(keyboard[l], l);
            }
        }else{
            var word = lines[j];
            var answer = 0;
            var b = 0;
            var c = 0;
            for(var h = 1; h < word.length; h++){
                b = a.get(word[h]);
                c = a.get(word[h - 1]);
                answer += Math.abs(b - c);
            }
            if(isNaN(answer)){
                answer = 0;
            }
            console.log(answer);
        }
    }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    console.log(typeof inputString)
    run(...inputString);
});

function readline() {
    return inputString[currentLine++];
}

const input = readline();

function run(...args) {
  console.log(args[1])
  const findDistance = (keyboard, word) => {
    const keyboardMap = {};
    for (let i = 0; i <= keyboard.length; i++) {
      if (!keyboardMap[keyboard[i]]) {
        keyboardMap[keyboard[i]] = i + 1;
      }
    }

    let sum = 0;
    for (let i = 1; i < word.length - 1; i++) {
      let firstValue = keyboardMap[word[i]];
      let secondValue = keyboardMap[word[i + 1]];

      if (firstValue > secondValue) {
        sum += firstValue - secondValue;
      } else {
        sum += secondValue - firstValue;
      }
    }
    return sum;
  };

  for (let i = 0; i < args.length - 1; i+=2) {
    const r = findDistance(args[i], args[i + 1]);
    console.log(r)

  }

}

function run(t, ...args) {
  const findDistance = (keyboard, word) => {
    const keyboardMap = {};
    for (let i = 0; i <= keyboard.length; i++) {
      if (!keyboardMap[keyboard[i]]) {
        keyboardMap[keyboard[i]] = i + 1;
      }
    }

    let sum = 0;
    for (let i = 0; i < word.length - 1; i++) {
      let firstValue = keyboardMap[word[i]];
      let secondValue = keyboardMap[word[i + 1]];

      if (firstValue > secondValue) {
        sum += firstValue - secondValue;
      } else {
        sum += secondValue - firstValue;
      }
    }
    return sum;
  };
  const res = [];
  for (let i = 0; i < args.length - 1; i+=2) {
    const r = findDistance(args[i], args[i + 1]);
    console.log(r)
    res.push(r);
  }
  return res;
}

run(5,
  'abcdefghijklmnopqrstuvwxyz',
  'hello',
  'abcdefghijklmnopqrstuvwxyz',
  'i',
  'abcdefghijklmnopqrstuvwxyz',
  'codeforces',
  'qwertyuiopasdfghjklzxcvbnm',
  'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq',
  'qwertyuiopasdfghjklzxcvbnm',
  'abacaba');

function run (t, ...args) {
  const findDistance = (keyboard, word) => {
    const keyboardMap = {};
    for (let i = 0; i <= keyboard.length; i++) {
      if (!keyboardMap[keyboard[i]]) {
          keyboardMap[keyboard[i]] = i+1;
      }
    }

   let sum = 0;
    for (let i =0; i < word.length -1; i++) {
      let firstValue = keyboardMap[word[i]];
      let secondValue = keyboardMap[word[i+1]];

      if (firstValue > secondValue) {
        sum += firstValue -secondValue;
      } else {
        sum += secondValue -firstValue;
      }
    }
    return sum;
  }
 const res = [];
  for (let i = 0; i < args.length - 1; i++) {
     res.push(findDistance(args[i], args[i+1]));
  }
  return res;
}

function run (t, ...args) {
  const findDistance = (keyboard, word) => {
    const keyboardMap = {};
    for (let i = 0; i <= keyboard.length; i++) {
      if (!keyboardMap[keyboard[i]]) {
          keyboardMap[keyboard[i]] = i+1;
      }
    }

   let sum = 0;
    for (let i =0; i < word.length -1; i++) {
      let firstValue = keyboardMap[word[i]];
      let secondValue = keyboardMap[word[i+1]];

      if (firstValue > secondValue) {
        sum += firstValue -secondValue;
      } else {
        sum += secondValue -firstValue;
      }
    }
    return sum;
  }

  for (let i = 0; i < args.length - 1; i++) {
     console.log(findDistance(args[i], args[i+1]));
  }

}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var a = new Map();
    for(var j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            a = new Map();
            var keyboard = lines[j];
            for(var l = 1; l < 27; l++){
                a.set(keyboard[l - 1], l);
            }
        }else{
            var word = lines[j];
            var answer = 0;
            var b = 0;
            var c = 0;
            for(var h = 1; h < word.length; h++){
                b = a.get(word[h]);
                c = a.get(word[h - 1]);
                answer += Math.abs(b - c);
            }
            console.log(answer - 1);
        }
    }
});


Little Vasya likes very much to play with sets consisting of positive integers. To make the game more interesting, Vasya chose n non-empty sets in such a way, that no two of them have common elements.One day he wanted to show his friends just how interesting playing with numbers is. For that he wrote out all possible unions of two different sets on n·(n - 1) / 2 pieces of paper. Then he shuffled the pieces of paper. He had written out the numbers in the unions in an arbitrary order.For example, if n = 4, and the actual sets have the following form {1, 3}, {5}, {2, 4}, {7}, then the number of set pairs equals to six. The six pieces of paper can contain the following numbers:   2, 7, 4.  1, 7, 3;  5, 4, 2;  1, 3, 5;  3, 1, 2, 4;  5, 7. Then Vasya showed the pieces of paper to his friends, but kept the n sets secret from them. His friends managed to calculate which sets Vasya had thought of in the first place. And how about you, can you restore the sets by the given pieces of paper?

The first input file line contains a number n (2 ≤ n ≤ 200), n is the number of sets at Vasya's disposal. Then follow sets of numbers from the pieces of paper written on n·(n - 1) / 2 lines. Each set starts with the number ki (2 ≤ ki ≤ 200), which is the number of numbers written of the i-th piece of paper, and then follow ki numbers aij (1 ≤ aij ≤ 200). All the numbers on the lines are separated by exactly one space. It is guaranteed that the input data is constructed according to the above given rules from n non-intersecting sets.

Print on n lines Vasya's sets' description. The first number on the line shows how many numbers the current set has. Then the set should be recorded by listing its elements. Separate the numbers by spaces. Each number and each set should be printed exactly once. Print the sets and the numbers in the sets in any order. If there are several answers to that problem, print any of them. It is guaranteed that there is a solution.

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  let M = ipt.split(EOL).slice(1, -1).map(l => l.split(' ').slice(1).map(v => parseInt(v)))

  if (M.length == 1) {
    console.log(`${M[0].length / 2 | 0} ${M[0].slice(0, M[0].length / 2 | 0).join(' ')}`)
    console.log(`${M[0].length - M[0].length / 2 | 0} ${M[0].slice(M[0].length / 2 | 0).join(' ')}`)
    return
  }

  let O = {}
  for (let i = 0; i < M.length; i++) {
    for (let j = 0; j < M[i].length; j++) {
      O[M[i][j]] = O[M[i][j]] || []
      O[M[i][j]].push(i)
    }
  }

  let I = {}
  for (const k in O) {
    let o = O[k]
    let ok = o.sort((a, b) => a - b).join(' ')
    I[ok] = I[ok] || []
    I[ok].push(k)
  }

  let R = []
  for (const k in I) {
    let i = I[k]
    console.log(`${i.length} ${i.join(' ')}`)
  }
})

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  let M = ipt.split(EOL).slice(1, -1).map(l => l.split(' ').slice(1).map(v => parseInt(v)))

  let O = {}
  for (let i = 0; i < M.length; i++) {
    for (let j = 0; j < M[i].length; j++) {
      O[M[i][j]] = O[M[i][j]] || []
      O[M[i][j]].push(i)
    }
  }

  let I = {}
  for (const k in O) {
    let o = O[k]
    let ok = o.sort((a, b) => a - b).join(' ')
    I[ok] = I[ok] || []
    I[ok].push(k)
  }

  let R = []
  for (const k in I) {
    let i = I[k]
    console.log(`${i.length} ${i.join(' ')}`)
  }
})


There are $$$n$$$ robbers at coordinates $$$(a_1, b_1)$$$, $$$(a_2, b_2)$$$, ..., $$$(a_n, b_n)$$$ and $$$m$$$ searchlight at coordinates $$$(c_1, d_1)$$$, $$$(c_2, d_2)$$$, ..., $$$(c_m, d_m)$$$. In one move you can move each robber to the right (increase $$$a_i$$$ of each robber by one) or move each robber up (increase $$$b_i$$$ of each robber by one). Note that you should either increase all $$$a_i$$$ or all $$$b_i$$$, you can't increase $$$a_i$$$ for some points and $$$b_i$$$ for some other points.Searchlight $$$j$$$ can see a robber $$$i$$$ if $$$a_i \leq c_j$$$ and $$$b_i \leq d_j$$$. A configuration of robbers is safe if no searchlight can see a robber (i.e. if there is no pair $$$i,j$$$ such that searchlight $$$j$$$ can see a robber $$$i$$$).What is the minimum number of moves you need to perform to reach a safe configuration?

The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 2000$$$): the number of robbers and the number of searchlight. Each of the next $$$n$$$ lines contains two integers $$$a_i$$$, $$$b_i$$$ ($$$0 \leq a_i, b_i \leq 10^6$$$), coordinates of robbers. Each of the next $$$m$$$ lines contains two integers $$$c_i$$$, $$$d_i$$$ ($$$0 \leq c_i, d_i \leq 10^6$$$), coordinates of searchlights.

Print one integer: the minimum number of moves you need to perform to reach a safe configuration.

NoteIn the first test, you can move each robber to the right three times. After that there will be one robber in the coordinates $$$(3, 0)$$$.The configuration of the robbers is safe, because the only searchlight can't see the robber, because it is in the coordinates $$$(2, 3)$$$ and $$$3 > 2$$$.In the second test, you can move each robber to the right two times and two times up. After that robbers will be in the coordinates $$$(3, 8)$$$, $$$(8, 3)$$$.It's easy the see that the configuration of the robbers is safe.It can be proved that you can't reach a safe configuration using no more than $$$3$$$ moves.

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let [n, m] = $(2)
  let a = Arr(n, i => ({ x: $(), y: $() }))
  let b = Arr(m, i => ({ x: $(), y: $() }))
  let y = Array(1e6 + 2).fill(0)
  For(n, i => {
    For(m, j => {
      if (a[i].x > b[j].x) return;
      y[b[j].x - a[i].x] = max(y[b[j].x - a[i].x], b[j].y - a[i].y + 1);
    })
  })
  let res = 1e10
  ForR(1e6 + 1, i => {
    y[i] = max(y[i], y[i + 1]);
    res = min(res, i + y[i])
  })
  log(res)
}


The problem describes the properties of a command line. The description somehow resembles the one you usually see in real operating systems. However, there are differences in the behavior. Please make sure you've read the statement attentively and use it as a formal document.In the Pindows operating system a strings are the lexemes of the command line — the first of them is understood as the name of the program to run and the following lexemes are its arguments. For example, as we execute the command " run.exe one, two . ", we give four lexemes to the Pindows command line: "run.exe", "one,", "two", ".". More formally, if we run a command that can be represented as string s (that has no quotes), then the command line lexemes are maximal by inclusion substrings of string s that contain no spaces.To send a string with spaces or an empty string as a command line lexeme, we can use double quotes. The block of characters that should be considered as one lexeme goes inside the quotes. Embedded quotes are prohibited — that is, for each occurrence of character """ we should be able to say clearly that the quotes are opening or closing. For example, as we run the command ""run.exe o" "" " ne, " two . " " ", we give six lexemes to the Pindows command line: "run.exe o", "" (an empty string), " ne, ", "two", ".", " " (a single space).It is guaranteed that each lexeme of the command line is either surrounded by spaces on both sides or touches the corresponding command border. One of its consequences is: the opening brackets are either the first character of the string or there is a space to the left of them.You have a string that consists of uppercase and lowercase English letters, digits, characters ".,?!"" and spaces. It is guaranteed that this string is a correct OS Pindows command line string. Print all lexemes of this command line string. Consider the character """ to be used only in order to denote a single block of characters into one command line lexeme. In particular, the consequence is that the given string has got an even number of such characters.

The single line contains a non-empty string s. String s consists of at most 105 characters. Each character is either an uppercase or a lowercase English letter, or a digit, or one of the ".,?!"" signs, or a space. It is guaranteed that the given string is some correct command line string of the OS Pindows. It is guaranteed that the given command line string contains at least one lexeme.

In the first line print the first lexeme, in the second line print the second one and so on. To make the output clearer, print the "<" (less) character to the left of your lexemes and the ">" (more) character to the right. Print the lexemes in the order in which they occur in the command. Please, follow the given output format strictly. For more clarifications on the output format see the test samples.

"RUn.exe O" "" "   2ne, " two! . " "
firstarg   second   ""

;(function () {

	print(function (s, result) {

		s = s.trim().split('');

		var word = '', isQuote = false;

		for (var i = 0, _i = s.length; i < _i; i++) {
			if (s[i] === '"') {
				if (isQuote) {
					result.push(['<', word, '>'].join(''));
					word = '';
				}

				isQuote = !isQuote;
			} else if (isQuote === false && s[i] === ' ') {
				word = word.trim();
				if (word.length) {
					result.push(['<', word, '>'].join(''));
				}
				word = '';
			} else {
				word += s[i];
			}
		}

		if (word.length) {
			result.push(['<', word, '>'].join(''));
		}

		return result.join('\n');

	}(readline(), []));

}.call(this));

//var command = '   firstarg   second   ""   '
var command = readline()
  , quoteOpen = false
  , spaceWas = false;
//print('command: ' + command);
command = ' ' + command;
for (var i = 0, lex = ''; i < command.length; i++) {
    if (command[i] === '"') {
        if (quoteOpen) {
            print("<"+lex+">");
            quoteOpen = false;
            spaceWas = false;
            lex = '';
        } else {
            quoteOpen = true;
            spaceWas = false;
            lex = '';
        }
    } else if (command[i] === ' ') {
        if (!quoteOpen) {
            if (!spaceWas) {
                spaceWas = true;
            } else if (command[i-1] !== ' '){
                print("<"+lex+">");
                lex = '';
            }
        } else {
            lex += command[i];
        }
    } else {
        lex += command[i];
    }
}
if (lex) print("<"+lex+">");

function main()
{
    var s = readline();
    var ans = "";
    var flag = false,
        quote = false;
    for ( var i = 0; i < s.length; i++ )
    {
        if ( s[i] == "\"" )
        {
            if ( quote )
            {
                print("<"+ans+">");
                ans = "";
            }
            quote = !quote;
        }
        else if ( !quote && s[i] == " " )
        {
            if ( ans.length )
            {
                print("<"+ans+">");
                ans = "";
            }
        }
        else
        {
            ans += s[i];
        }
    }
    if ( ans != "" )
        print("<"+ans+">");
}

main();

function main()
{
    var s = readline();
    var ans = "";
    var flag = false,
        quote = false;
    for ( var i = 0; i < s.length; i++ )
    {
        if ( !flag )
        {
            if ( s[i] == "\"" )
            {
                flag = true;
                quote = true;
            }
            else if ( s[i] != " " )
            {
                ans += s[i];
                flag = true;
            }
        }
        else
        {
            if ( quote == true )
            {
                if ( s[i] == "\"" )
                {
                    print("<"+ans+">");
                    ans = "";
                    flag = false;
                    quote = false;
                }
                else
                {
                    ans += s[i];
                }
            }
            else
            {
                if ( s[i] == " " )
                {
                    print("<"+ans+">");
                    ans = "";
                    flag = false;
                    quote = false;
                }
                else
                {
                    ans += s[i];
                }
            }
        }
    }
    if ( ans != "" )
        print("<"+ans+">");
}

main();

function main(){
    var s = readline();
    var ans = "";
    var flag = false,
        quote = false;
    for ( var i = 0; i < s.length; i++ ){
        if ( s[i] == "\"" ){
            if ( quote ){
                print("<"+ans+">");
                ans = "";
            }
            quote = !quote;
        }
        else if ( !quote && s[i] == " " ){
            if ( ans.length ){
                print("<"+ans+">");
                ans = "";
            }
        }
        else{
            ans += s[i];
        }
    }
    if ( ans != "" )
        print("<"+ans+">");
}

main();

;(function () {

	print(function (s, result) {

		s = s.trim().split('');

		var word = '', isQuote = false;

		for (var i = 0, _i = s.length; i < _i; i++) {
			if (s[i] === '"') {
				if (isQuote) {
					isQuote = false;
					result.push(['<', word, '>'].join(''));
					word = '';
				} else {
					isQuote = true;
				}
			} else if (isQuote === false && s[i] === ' ') {
				word = word.trim();
				if (word.length) result.push(['<', word, '>'].join(''));
				word = '';
			} else {
				word += s[i];
			}
		}

		return result.join('\n');

	}(readline(), []));

}.call(this));

//var command = '   firstarg   second   ""   '
var command = readline()
  , quoteOpen = false
  , spaceWas = false;

for (var i = 0, lex = ''; i < command.length; i++) {
    if (command[i] === '"') {
        if (quoteOpen) {
            print("<"+lex+">");
            quoteOpen = false;
            spaceWas = false;
            lex = '';
        } else {
            quoteOpen = true;
            spaceWas = false;
            lex = '';
        }
    } else if (command[i] === ' ') {
        if (!quoteOpen) {
            if (!spaceWas) {
                spaceWas = true;
                lex = '';
            } else if (command[i-1] !== ' '){
                print("<"+lex+">");
                lex = '';
            }
        } else {
            lex += command[i];
        }
    } else {
        lex += command[i];
    }
}

//var command = '   firstarg   second   ""   '
var command = readline()
  , quoteOpen = false
  , spaceWas = false;
//print('command: ' + command);
for (var i = 0, lex = ''; i < command.length; i++) {
    if (command[i] === '"') {
        if (quoteOpen) {
            print("<"+lex+">");
            quoteOpen = false;
            spaceWas = false;
            lex = '';
        } else {
            quoteOpen = true;
            spaceWas = false;
            lex = '';
        }
    } else if (command[i] === ' ') {
        if (!quoteOpen) {
            if (!spaceWas) {
                spaceWas = true;
                lex = '';
            } else if (command[i-1] !== ' '){
                print("<"+lex+">");
                lex = '';
            }
        } else {
            lex += command[i];
        }
    } else {
        lex += command[i];
    }
}
if (lex) print("<"+lex+">");

//var command = '   firstarg   second   ""   '
var command = readline()
  , quoteOpen = false
  , spaceWas = false;
//print('command' + command);
for (var i = 0, lex = ''; i < command.length; i++) {
    if (command[i] === '"') {
        if (quoteOpen) {
            print("<"+lex+">");
            quoteOpen = false;
            spaceWas = false;
            lex = '';
        } else {
            quoteOpen = true;
            spaceWas = false;
            lex = '';
        }
    } else if (command[i] === ' ') {
        if (!quoteOpen) {
            if (!spaceWas) {
                spaceWas = true;
                lex = '';
            } else if (command[i-1] !== ' '){
                print("<"+lex+">");
                lex = '';
            }
        } else {
            lex += command[i];
        }
    } else {
        lex += command[i];
    }
}
if (lex) print("<"+lex+">");

//var command = '   firstarg   second   ""   '
var command = readline()
  , quoteOpen = false
  , spaceWas = false;
print('command: ' + command);
for (var i = 0, lex = ''; i < command.length; i++) {
    if (command[i] === '"') {
        if (quoteOpen) {
            print("<"+lex+">");
            quoteOpen = false;
            spaceWas = false;
            lex = '';
        } else {
            quoteOpen = true;
            spaceWas = false;
            lex = '';
        }
    } else if (command[i] === ' ') {
        if (!quoteOpen) {
            if (!spaceWas) {
                spaceWas = true;
            } else if (command[i-1] !== ' '){
                print("<"+lex+">");
                lex = '';
            }
        } else {
            lex += command[i];
        }
    } else {
        lex += command[i];
    }
}
if (lex) print("<"+lex+">");

//var command = '   firstarg   second   ""   '
var command = readline()
  , quoteOpen = false
  , spaceWas = false;
//print('command: ' + command);
for (var i = 0, lex = ''; i < command.length; i++) {
    if (command[i] === '"') {
        if (quoteOpen) {
            print("<"+lex+">");
            quoteOpen = false;
            spaceWas = false;
            lex = '';
        } else {
            quoteOpen = true;
            spaceWas = false;
            lex = '';
        }
    } else if (command[i] === ' ') {
        if (!quoteOpen) {
            if (!spaceWas) {
                spaceWas = true;
            } else if (command[i-1] !== ' '){
                print("<"+lex+">");
                lex = '';
            }
        } else {
            lex += command[i];
        }
    } else {
        lex += command[i];
    }
}
if (lex) print("<"+lex+">");

function main()
{
    var s = readline();
    var ans = "";
    var flag = false,
        quote = false;
    for ( var i = 0; i < s.length; i++ )
    {
        if ( !flag )
        {
            if ( s[i] == "\"" )
            {
                flag = true;
                quote = true;
            }
            else if ( s[i] != " " )
            {
                ans += s[i];
                flag = true;
            }
        }
        else
        {
            if ( quote == true )
            {
                if ( s[i] == "\"" )
                {
                    print("<"+ans+">");
                    ans = "";
                    flag = false;
                    quote = false;
                }
                else
                {
                    ans += s[i];
                }
            }
            else
            {
                if ( s[i] == " " )
                {
                    print("<"+ans+">");
                    ans = "";
                    flag = false;
                    quote = false;
                }
                else
                {
                    ans += s[i];
                }
            }
        }
    }
}

main();


Daniel is watching a football team playing a game during their training session. They want to improve their passing skills during that session.The game involves $$$n$$$ players, making multiple passes towards each other. Unfortunately, since the balls were moving too fast, after the session Daniel is unable to know how many balls were involved during the game. The only thing he knows is the number of passes delivered by each player during all the session.Find the minimum possible amount of balls that were involved in the game.

There are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 5 \cdot 10^4$$$) — the number of test cases. This is followed by the test cases description. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the number of players. The second line of the test case contains a sequence of integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$), where $$$a_i$$$ is the number of passes delivered by the $$$i$$$-th player. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case print a single integer — the answer to the problem.

NoteIn the first test case, with the only ball, the game can go like this:$$$2 \rightarrow 1 \rightarrow 3 \rightarrow 4 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 2 \rightarrow 3 \rightarrow 2$$$.In the second test case, there is no possible way to play the game with only one ball. One possible way to play with two balls:$$$2 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 1$$$.$$$2 \rightarrow 3 \rightarrow 2 \rightarrow 1$$$In the third example, there were no passes, so $$$0$$$ balls are possible.

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let max = 0,
      sum = 0;
    for (let i = 0; i < n; i++) {
      max = Math.max(max, arr[i]);
      sum += arr[i];
    }
    if (sum === 0) console.log(0);
    else {
      sum = sum - max;
      if (sum >= max - 1) console.log(1);
      else console.log(1 + (max - sum - 1));
    }
  }
};
solve();

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value;
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		let mx = Math.max(...a);

		let sum = 0;
		for (let i = 0; i < n; i++) sum += a[i];
		sum -= mx;

		let ans;
		if (mx == 0) ans = 0;
		else if (sum >= mx) ans = 1;
		else ans = mx - sum;

		console.log(ans);
	}
}

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value;
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		a.sort((x, y) => x - y);

		let sum = 0;
		for (let i = 0; i < n - 1; i++) sum += a[i];

		let ans = 0;
		if (sum + a[n-1])
			ans = 1 + Math.max(a[n-1] - sum - 1, 0);

		console.log(ans);
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var map = {};
		var max = 0;
		var K = 0;
		for(var i = 0; i < N; i++){
			K += list[i];
			max = Math.max(max, list[i]);
		}
		if(K == 0){
			myout(0);
			continue;
		}
		var output = 0;
		for(var i = 0; i < N; i++){
			output = Math.max(output, max - 1 - (K - list[i]));
		}
		myout(output + 1);
	}
}

function solve() {
   const n = Number(read());
   const arr = readArray(BigInt);
   let maxNum = 0n;
   let sumNum = 0n;
   for (const x of arr) {
      sumNum += x;
      if (x > maxNum) {
         maxNum = x;
      }
   }
   if (sumNum === 0n) {
      write(0);
      return;
   }
   sumNum -= maxNum;
   if (maxNum <= sumNum + 1n) {
      write(1);
      return;
   }
   write(maxNum - sumNum);
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function pDivCount(n) {
   let ans = 0;
   let i = 1;
   while(n > 1) {
      i++;
      while(n % i === 0) {
         ans++;
         n = Math.floor(n / i);
      }
   }
   return ans;
}

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

function init() {
   try {
      var T;
      T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e);
   }
}

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on("end", (_) => {
  inputString = inputString
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function main() {
  const testCases = readline();

  for (let i = 0; i < testCases; i++) {
    let size = readline();
    let arr = readline().split(" ").map(Number);

    let max = -1;
    let sum = 0;
    for (let j = 0; j < arr.length; j++) {
      if (arr[j] > max) max = arr[j];
      sum += arr[j];
    }
    let sumMinusMax = sum - max;
    // console.log(sum, max);
    if (sum === 0) {
      console.log(0);
    } else if (sumMinusMax >= max) {
      console.log(1);
    } else {
      console.log(max - sumMinusMax);
    }
  }
}

function readLineNums () {
  return readline().split(' ').map(x => parseInt(x));
}

// ***** PROBLEM SOLUTION *****

var n = readLineNums();

while (n--) {
  readLineNums();
  var passes = readLineNums();

  if ( !passes.some(pass => pass !== 0) ) {
    print(0);
    continue;
  }
  var max = passes.reduce((max, num) => (num > max) ? num : max, -1);
  var sum = passes.reduce((sum, num) => (num + sum), 0);

  var remaining = sum - max;

  if (remaining >= max) {
    print(1);
  } else {
    print(2 * max - sum);
  }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    arr.sort((a, b) => b - a);
    if (arr[0] === 0) {
      console.log(0);
      continue;
    }
    let ans = 0;
    for (let i = 1; i < n; i++) {
      let dif = Math.abs(arr[i] - arr[i - 1]);
      if (dif <= 0) arr[i] = 1;
      else arr[i] = dif;
    }
    if (arr[n - 1] <= 1) console.log(1);
    else console.log(arr[n - 1]);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    arr.sort((a, b) => b - a);
    if (arr[0] === 0) {
      console.log(0);
      continue;
    }
    let ans = 0;
    for (let i = 1; i < n; i++) {
      let dif = Math.abs(arr[i] - arr[i - 1]);
      if (dif <= 0) arr[i] = 0;
      else arr[i] = dif;
    }
    if (arr[n - 1] <= 1) console.log(1);
    else console.log(arr[n - 1]);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    arr.sort((a, b) => b - a);
    if (arr[n - 1] === 0) {
      console.log(0);
      continue;
    }
    let ans = 0;
    for (let i = 1; i < n; i++) {
      let dif = Math.abs(arr[i] - arr[i - 1]);
      if (dif <= 0) arr[i] = 0;
      else arr[i] = dif;
    }
    if (arr[n - 1] <= 1) console.log(1);
    else console.log(arr[n - 1]);
  }
};
solve();

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value;
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		a.sort((x, y) => x - y);

		let sum = 0;
		for (let i = 0; i < n - 1; i++) sum += a[i];

		let ans = 0;
		if (sum)
			ans = 1 + Math.max(a[n-1] - sum - 1, 0);

		console.log(ans);
	}
}


Indian summer is such a beautiful time of the year! A girl named Alyona is walking in the forest and picking a bouquet from fallen leaves. Alyona is very choosy — she doesn't take a leaf if it matches the color and the species of the tree of one of the leaves she already has. Find out how many leaves Alyona has picked.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of leaves Alyona has found. The next n lines contain the leaves' descriptions. Each leaf is characterized by the species of the tree it has fallen from and by the color. The species of the trees and colors are given in names, consisting of no more than 10 lowercase Latin letters. A name can not be an empty string. The species of a tree and the color are given in each line separated by a space.

Output the single number — the number of Alyona's leaves.

5
birch yellow
maple red
birch yellow
maple yellow
maple green

var readline=require('readline');
var rl=readline.createInterface(process.stdin,process.stdout);
var n=-1;
var checker=0;
var mySet=new Set();
rl.on('line', lineInput => {
    if(n==-1){
      n=parseInt(lineInput);
    }
    else{
      mySet.add(lineInput);
      checker++;
      if(checker==n){
      console.log(mySet.size);
      rl.close();
      }
    }

});

/*  inputs.push(lineInput);
const n=parseInt(lineInput);
for(let i=0; i<n; i++){
  mySet.add(lineInput);
}
Console.log(mySet.size());*/

'use strict'

let N = +readline()
let lll

let ls = new Set
while (lll = readline()) {
  ls.add(lll)
}

print(ls.size)