You are given the strings $$$a$$$ and $$$b$$$, consisting of lowercase Latin letters. You can do any number of the following operations in any order:   if $$$|a| > 0$$$ (the length of the string $$$a$$$ is greater than zero), delete the first character of the string $$$a$$$, that is, replace $$$a$$$ with $$$a_2 a_3 \ldots a_n$$$;  if $$$|a| > 0$$$, delete the last character of the string $$$a$$$, that is, replace $$$a$$$ with $$$a_1 a_2 \ldots a_{n-1}$$$;  if $$$|b| > 0$$$ (the length of the string $$$b$$$ is greater than zero), delete the first character of the string $$$b$$$, that is, replace $$$b$$$ with $$$b_2 b_3 \ldots b_n$$$;  if $$$|b| > 0$$$, delete the last character of the string $$$b$$$, that is, replace $$$b$$$ with $$$b_1 b_2 \ldots b_{n-1}$$$. Note that after each of the operations, the string $$$a$$$ or $$$b$$$ may become empty.For example, if $$$a=$$$"hello" and $$$b=$$$"icpc", then you can apply the following sequence of operations:   delete the first character of the string $$$a$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"icpc";  delete the first character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"cpc";  delete the first character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ello" and $$$b=$$$"pc";  delete the last character of the string $$$a$$$ $$$\Rightarrow$$$ $$$a=$$$"ell" and $$$b=$$$"pc";  delete the last character of the string $$$b$$$ $$$\Rightarrow$$$ $$$a=$$$"ell" and $$$b=$$$"p". For the given strings $$$a$$$ and $$$b$$$, find the minimum number of operations for which you can make the strings $$$a$$$ and $$$b$$$ equal. Note that empty strings are also equal.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$). Then $$$t$$$ test cases follow. The first line of each test case contains the string $$$a$$$ ($$$1 \le |a| \le 20$$$), consisting of lowercase Latin letters. The second line of each test case contains the string $$$b$$$ ($$$1 \le |b| \le 20$$$), consisting of lowercase Latin letters.

For each test case, output the minimum number of operations that can make the strings $$$a$$$ and $$$b$$$ equal.

5
a
a
abcd
bc
hello
codeforces
hello
helo
dhjakjsnasjhfksafasd
adjsnasjhfksvdafdser

"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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let s1 = readline().trim().split("");
    let s2 = readline().trim().split("");
    if (s1.length < s2.length) [s1, s2] = [s2, s1];
    let cnt = 0;
    for (let i = 0; i < s1.length; i++) {
      let k = i;
      for (let j = 0; j < s2.length; j++) {
        let s = j,
          k = i,
          tp = 0;
        while (k < s1.length && s1[k] === s2[s]) {
          tp++;
          k++;
          s++;
        }
        cnt = Math.max(cnt, tp);
      }
    }
    if (cnt === s1.length && cnt === s2.length) console.log(0);
    else console.log(s1.length + s2.length - cnt * 2);
  }
};
solve();

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
///////////////////////////////////////////////////////////////////////////////////

const solve = (a, b) => {
    let res = LongestCommonSubstringLen(a, b);
    pr(a.length + b.length - res * 2);
};

const LongestCommonSubstringLen = (A, B) => {
    let m = A.length;
    let n = B.length;
    let maxLen = 0;
    let dp = initialize2DArrayNew(m + 1, n + 1);
    for (let i = 1; i <= m; i++) {
        for (let j = 1; j <= n; j++) {
            if (A[i - 1] == B[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                if (dp[i][j] > maxLen) {
                    maxLen = dp[i][j];
                }
            }
        }
    }
    return maxLen;
};

const initialize2DArrayNew = (m, n) => {
    let data = [];
    for (let i = 0; i < m; i++) {
        let tmp = new Array(n).fill(0);
        data.push(tmp);
    }
    return data;
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
const mx = Math.max;
///////////////////////////////////////////////////////////////////////////////////

const solve = (a, b) => {
    let res = LongestCommonSubstring(a, b).length;
    pr(a.length + b.length - res * 2);
};

const LongestCommonSubstring = (A, B) => {
    let m = A.length;
    let n = B.length;
    let maxLen = 0;
    let endIdx = m;
    let dp = initialize2DArrayNew(m + 1, n + 1);
    for (let i = 1; i <= m; i++) {
        for (let j = 1; j <= n; j++) {
            if (A[i - 1] == B[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                if (dp[i][j] > maxLen) {
                    maxLen = dp[i][j];
                    endIdx = i;
                }
            }
        }
    }
    return A.slice(endIdx - maxLen, endIdx);
};

const initialize2DArrayNew = (m, n) => {
    let data = [];
    for (let i = 0; i < m; i++) {
        let tmp = new Array(n).fill(0);
        data.push(tmp);
    }
    return data;
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

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

let TC = 0;
let A, B;
readline.on('line', line => {
    if (TC === 0) {
        TC = Number(line.toString());
        return;
    }
    if (!A) {
        A = line.toString();
        return;
    }
    B = line.toString();
    if (A.length > B.length) {
        [B, A] = [A, B];
    }
    let maxMatchLength = 0;
    for (let i = 0; i < A.length; i++) {
        for (let j = 1; j < A.length - i + 1; j++) {
            const t = A.substr(i, j);
            if (B.indexOf(t) > -1) {
                const matchLength = t.length;
                if (maxMatchLength < matchLength) {
                    maxMatchLength = matchLength;
                }
            }
        }
    }
    console.log((A.length - maxMatchLength) + (B.length - maxMatchLength));

    A = undefined; B = undefined;
    TC--;
    if (TC === 0) {
        process.exit();
    }
});

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
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

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

// ********** Code Start **********
const getStringByLength = (strA, strB) => {
  const lenA = strA.length;
  const lenB = strB.length;

  if (lenA < lenB) return [strA, strB];

  return [strB, strA];
};
function main() {
  let num = parseInt(readline());
  while (num--) {
    let str1 = readline();
    let str2 = readline();
    const [strA, strB] = getStringByLength(str1, str2);
    let start = 0;
    let max = 0;
    for (let i = 0; i < strA.length; i++) {
      if (strB.includes(strA.substring(start, i + 1))) {
        max = Math.max(max, i - start + 1);
      } else start++;
    }
    print(strA.length - max + strB.length - max);
  }
}

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
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

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

// ********** Code Start **********
const getStringByLength = (strA, strB) => {
  const lenA = strA.length;
  const lenB = strB.length;

  if (lenA < lenB) return [strA, strB];

  return [strB, strA];
};
function main() {
  var num = parseInt(readline())
	while(num--){
    var str1 = readline()
    var str2 = readline()
    const [strA, strB] = getStringByLength(str1, str2)
    var start = 0
    var max = 0
    for(let i = 0; i < strA.length;i++){
      if(strB.includes(strA.substring(start, i + 1))){
        max = Math.max(max, i - start +1)
      }
      else start++
    }
    print(strA.length - max + strB.length - max)
  }
}

'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++];
}

const getStringByLength = (strA, strB) => {
  const lenA = strA.length;
  const lenB = strB.length;

  if (lenA < lenB) return [strA, strB];

  return [strB, strA];
};

const main = () => {
  const rows = parseInt(readline());

  for (let idx = 0; idx < rows; idx++) {
    const wordA = readline();
    const wordB = readline();

    const [strA, strB] = getStringByLength(wordA, wordB);
    let startPos = 0;
    let maxLength = 0;
    for (let jdx = 0; jdx < strA.length; jdx++) {
      const wordSoFar = strA.substring(startPos, jdx + 1);
      if (strB.includes(wordSoFar)) {
        maxLength = Math.max(maxLength, jdx - startPos + 1);
      } else {
        startPos += 1;
      }
    }

    const answer = strA.length - maxLength + strB.length - maxLength;
    console.log(answer);
  }
};

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function solve() {
   var a = read();
   var b = read();
   var maxCommon = 0;
   for (var as = 0; as < a.length; as++) {
      for (var af = as + 1; af <= a.length; af++) {
         for (var bs = 0; bs < b.length; bs++) {
            for (var bf = bs + 1; bf <= b.length; bf++) {
               if (bf - bs !== af - as) {
                  continue;
               }
               if (a.substring(as, af) !== b.substring(bs, bf)) {
                  continue;
               }
               if (af - as > maxCommon) {
                  maxCommon = af - as;
               }
            }
         }
      }
   }
   write(a.length + b.length - maxCommon * 2);
}

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

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

function readArray(f) {
   return read().split(' ').map(f);
}

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var n = Number(input[0]);
    var j = 1;
    for (let i = 1; i <= n; i++) {
        var str1 = input[j];
        j++;
        var str2 = input[j];
        j++;
        function minOperation(str1, str2) {
            var max = 0;
            for (var i = 0; i < str1.length; i++) {
                var str = "";
                for (var j = i; j < str1.length; j++) {
                    str += str1[j];
                    if (str2.indexOf(str) >= 0) {
                        max = Math.max(max, str.length);
                    }
                }
            }
            return (str1.length - max) + (str2.length - max);
        }
        console.log(minOperation(str1, str2));
    }
})

const {EOL} = require('os');
let i = ''
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
  main(i);
})

function circularShift(str) {
  return str[str.length - 1] + str.slice(0, str.length - 1);
}

function getEqualityArray(shortString, longString) {
  let res = [], max = 0, len = 0;;
  for (let i = 0; i < shortString.length; i++) {
    if (shortString[i] === longString[i]) {
      if (shortString[i] === '$') {
        res.push('$');
        len = 0;
      } else {
        res.push(1);
        len++;
      }
    } else {
      res.push(0);
      len = 0;
    }
    if (len > max) max = len;
  }
  return {arr: res, max: max};
}

function getLcsLength(str1, str2) {
  if (str1 === str2) return str1.length;
  let shortString, longString;
  if (str1.length <= str2.length) {
    shortString = str1 + '$';
    longString = str2 + '$';
  } else {
    shortString = str2 + '$';
    longString = str1 + '$';
  }
  let maxLCSLength = 0;
  let longStringCopy = longString;

  for (let i = 0; i < longStringCopy.length; i++) {
    let ea = getEqualityArray(shortString, longStringCopy);
    if (ea.max > maxLCSLength) maxLCSLength = ea.max;
    longStringCopy = circularShift(longStringCopy);
  }

  return maxLCSLength;
}

function findMinChanges(a, b) {
  const lcs = getLcsLength(a, b);
  return a.length + b.length - 2 * lcs
}

function main (input) {
  let index = 0;
  const lines = input.split(EOL);

  const t = lines[index++];

  for (let i = 0; i < t; i++) {
    let a = lines[index++];
    let b = lines[index++];
    console.log(findMinChanges(a, b));
  }
}

//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var a = next();
		var b = next();
		var count = a.length + b.length;
		for(var j = 0; j < a.length; j++){
			for(var k = j; k < a.length; k++){
				var na = a.substring(j, k + 1);
				for(var l = 0; l < b.length; l++){
					for(var m = l; m < b.length; m++){
						var nb = b.substring(l, m + 1);
						if(na == nb){
							count = Math.min(count, (a.length - na.length) + (b.length - nb.length));
						}
					}
				}
			}
		}
		myout(count);
	}
}

'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++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {

    var a = readline()
    var b = readline()
    var string = longestCommonSubstring(a,b)

    // if(!string) return console.log(a.length + b.length)

    console.log(a.length + b.length - 2*string.length)
  })
}
function longestCommonSubstring(string1, string2) {
  // Convert strings to arrays to treat unicode symbols length correctly.
  // For example:
  // '𐌵'.length === 2
  // [...'𐌵'].length === 1
  const s1 = [...string1];
  const s2 = [...string2];

  // Init the matrix of all substring lengths to use Dynamic Programming approach.
  const substringMatrix = Array(s2.length + 1).fill(null).map(() => {
    return Array(s1.length + 1).fill(null);
  });

  // Fill the first row and first column with zeros to provide initial values.
  for (let columnIndex = 0; columnIndex <= s1.length; columnIndex += 1) {
    substringMatrix[0][columnIndex] = 0;
  }

  for (let rowIndex = 0; rowIndex <= s2.length; rowIndex += 1) {
    substringMatrix[rowIndex][0] = 0;
  }

  // Build the matrix of all substring lengths to use Dynamic Programming approach.
  let longestSubstringLength = 0;
  let longestSubstringColumn = 0;
  let longestSubstringRow = 0;

  for (let rowIndex = 1; rowIndex <= s2.length; rowIndex += 1) {
    for (let columnIndex = 1; columnIndex <= s1.length; columnIndex += 1) {
      if (s1[columnIndex - 1] === s2[rowIndex - 1]) {
        substringMatrix[rowIndex][columnIndex] = substringMatrix[rowIndex - 1][columnIndex - 1] + 1;
      } else {
        substringMatrix[rowIndex][columnIndex] = 0;
      }

      // Try to find the biggest length of all common substring lengths
      // and to memorize its last character position (indices)
      if (substringMatrix[rowIndex][columnIndex] > longestSubstringLength) {
        longestSubstringLength = substringMatrix[rowIndex][columnIndex];
        longestSubstringColumn = columnIndex;
        longestSubstringRow = rowIndex;
      }
    }
  }

  if (longestSubstringLength === 0) {
    // Longest common substring has not been found.
    return '';
  }

  // Detect the longest substring from the matrix.
  let longestSubstring = '';

  while (substringMatrix[longestSubstringRow][longestSubstringColumn] > 0) {
    longestSubstring = s1[longestSubstringColumn - 1] + longestSubstring;
    longestSubstringRow -= 1;
    longestSubstringColumn -= 1;
  }

  return longestSubstring;
}

"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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let s1 = readline().trim().split("");
    let s2 = readline().trim().split("");
    let cnt = 0;
    for (let i = 0; i < s1.length; i++) {
      let k = 0,
        l = i;
      for (let j = 0; j < s2.length; j++) {
        if (s2[j] === s1[l] && l < s1.length) {
          k++;
          l++;
        } else {
          cnt = Math.max(cnt, k);
          l = i;
          if (k !== 0) j--;
          k = 0;
        }
      }
      cnt = Math.max(cnt, k);
    }
    if (cnt === s1.length && cnt === s2.length) console.log(0);
    else console.log(s1.length + s2.length - cnt * 2);
  }
};
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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let s1 = readline().trim().split("");
    let s2 = readline().trim().split("");
    let cnt = 0;
    for (let i = 0; i < s1.length; i++) {
      let k = 0,
        l = i;
      for (let j = 0; j < s2.length; j++) {
        if (s2[j] === s1[l] && l < s1.length) {
          k++;
          l++;
        } else {
          cnt = Math.max(cnt, k);
          l = i;
          k = 0;
        }
      }
      cnt = Math.max(cnt, k);
    }
    if (cnt === s1.length && cnt === s2.length) console.log(0);
    else console.log(s1.length + s2.length - cnt * 2);
  }
};
solve();

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
const mx = Math.max;
///////////////////////////////////////////////////////////////////////////////////

const solve = (a, b) => {
    let an = a.length;
    let bn = b.length;
    an <= bn ? go(a, b) : go(b, a);
};

const go = (short, long) => {
    let sn = short.length;
    let ln = long.length;
    if (sn == ln && short == long) return pr(0);
    if (long.indexOf(short) != -1) return pr(sn);
    let res = 0;
    for (let i = 0; i < sn; i++) {
        for (let j = i; j < sn; j++) {
            let len = j - i + 1;
            let sub = short.slice(i, j + 1);
            if (long.indexOf(sub) != -1) {
                res = mx(res, len);
            }
        }
    }
    pr(sn + ln - res * 2);
}

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

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

let TC = 0;
let A, B;
readline.on('line', line => {
    if (TC === 0) {
        TC = Number(line.toString());
        return;
    }
    if (!A) {
        A = line.toString();
        return;
    }
    B = line.toString();
    if (A.length > B.length) {
        [B, A] = [A, B];
    }
    let maxMatchLength = 0;
    for (let i = 0; i < A.length; i++) {
        for (let j = i + 1; j < A.length - i; j++) {
            const t = A.substr(i, j);
            if (B.indexOf(t) > -1) {
                const matchLength = t.length;
                if (maxMatchLength < matchLength) {
                    maxMatchLength = matchLength;
                }
            }
        }
    }
    console.log((A.length - maxMatchLength) + (B.length - maxMatchLength));

    A = undefined; B = undefined;
    TC--;
    if (TC === 0) {
        process.exit();
    }
});


You are given a permutation $$$p_1, p_2, \dots, p_n$$$. A permutation of length $$$n$$$ is a sequence such that each integer between $$$1$$$ and $$$n$$$ occurs exactly once in the sequence.Find the number of pairs of indices $$$(l, r)$$$ ($$$1 \le l \le r \le n$$$) such that the value of the median of $$$p_l, p_{l+1}, \dots, p_r$$$ is exactly the given number $$$m$$$.The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used.For example, if $$$a=[4, 2, 7, 5]$$$ then its median is $$$4$$$ since after sorting the sequence, it will look like $$$[2, 4, 5, 7]$$$ and the left of two middle elements is equal to $$$4$$$. The median of $$$[7, 1, 2, 9, 6]$$$ equals $$$6$$$ since after sorting, the value $$$6$$$ will be in the middle of the sequence.Write a program to find the number of pairs of indices $$$(l, r)$$$ ($$$1 \le l \le r \le n$$$) such that the value of the median of $$$p_l, p_{l+1}, \dots, p_r$$$ is exactly the given number $$$m$$$.

The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2\cdot10^5$$$, $$$1 \le m \le n$$$) — the length of the given sequence and the required value of the median. The second line contains a permutation $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$). Each integer between $$$1$$$ and $$$n$$$ occurs in $$$p$$$ exactly once.

NoteIn the first example, the suitable pairs of indices are: $$$(1, 3)$$$, $$$(2, 2)$$$, $$$(2, 3)$$$ and $$$(2, 4)$$$.

s=readline().split(' ')
n=+s[0]
m=+s[1]
a=readline().split(' ').map(function(x){return(+x)});
d=-1
for (i=0;i<n;i++)
{
    if (a[i]==m)
    {
        d=i;
    }
}
dp=new Array(2*n+15)
for (i=0;i<2*n+15;i++)
{
    dp[i]=0
}
now=0
for (i=d;i<n;i++)
{
    if (a[i]>m)
        ++now
    if (a[i]<m)
        --now
    dp[now+n]++;
}
res=0
now=0
for (i=d;i>=0;i--)
{
    if (a[i]>m)
        --now
    if (a[i]<m)
        ++now
    res+=dp[now+n];
    res+=dp[now+1+n];
}
print(res)


There is a string s, consisting of capital Latin letters. Let's denote its current length as |s|. During one move it is allowed to apply one of the following operations to it:   INSERT pos ch — insert a letter ch in the string s in the position pos (1 ≤ pos ≤ |s| + 1, A ≤ ch ≤ Z). The letter ch becomes the pos-th symbol of the string s, at that the letters shift aside and the length of the string increases by 1.  DELETE pos — delete a character number pos (1 ≤ pos ≤ |s|) from the string s. At that the letters shift together and the length of the string decreases by 1.  REPLACE pos ch — the letter in the position pos of the line s is replaced by ch (1 ≤ pos ≤ |s|, A ≤ ch ≤ Z). At that the length of the string does not change. Your task is to find in which minimal number of moves one can get a t string from an s string. You should also find the sequence of actions leading to the required results.

The first line contains s, the second line contains t. The lines consist only of capital Latin letters, their lengths are positive numbers from 1 to 1000.

In the first line print the number of moves k in the given sequence of operations. The number should be the minimal possible one. Then print k lines containing one operation each. Print the operations in the format, described above. If there are several solutions, print any of them.

10
REPLACE 1 W
REPLACE 2 R
REPLACE 3 O
REPLACE 4 N
REPLACE 5 G
REPLACE 6 A
INSERT 7 N
INSERT 8 S
INSERT 9 W
REPLACE 11 R

function main(a, b) {
  // define variables
  var config = {
    sources: {
      insert: 0,
      remove: 1,
      matching: 2,
    },
    scores: {
      match: 0,
      replace: -1,
      insert: -1,
      remove: -1
    },
  };
  function create() {
    var table = [];
    for (var i = 0; i < a.length + 1; i++) {
      var row = [];
      for (var j = 0; j < b.length + 1; j++) {
        row.push(null);
      }
      table.push(row);
    }
    return table;
  }
  var scores = create();
  var sources = create();
  var letters = create();

  // compute first row and first column
  scores[0][0] = 0;
  for (var i = 0; i < a.length; i++) {
    scores[i + 1][0] = (i + 1) * config.scores.remove;
    sources[i + 1][0] = config.sources.remove;
    letters[i + 1][0] = a[i];
  }
  for (var i = 0; i < b.length; i++) {
    scores[0][i + 1] = (i + 1) * config.scores.insert;
    sources[0][i + 1] = config.sources.insert;
    letters[0][i + 1] = b[i];
  }

  // compute the whole table
  for (var i = 1; i < scores.length; i++) {
    for (var j = 1; j < scores[i].length; j++) {
      var match = a[i - 1] === b[j - 1];
      var insertScore = scores[i][j - 1] + config.scores.insert;
      var removeScore = scores[i - 1][j] + config.scores.remove;
      var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];

      if (insertScore >= removeScore && insertScore >= matchingScore) {
        scores[i][j] = insertScore;
        sources[i][j] = config.sources.insert;
        letters[i][j] = b[j - 1];
      } else if (removeScore >= insertScore && removeScore >= matchingScore) {
        scores[i][j] = removeScore;
        sources[i][j] = config.sources.remove;
        letters[i][j] = a[i - 1];
      } else if (matchingScore >= removeScore && matchingScore >= insertScore) {
        scores[i][j] = matchingScore;
        sources[i][j] = config.sources.matching;
        letters[i][j] = match ? ' ' : b[j - 1];
      }
    }
  }

  // return the editing operation list
  var path = [];
  var j = b.length;
  var i = a.length;
  var current = a.slice();
  while (i > 0 || j > 0) {
    if (sources[i][j] === config.sources.matching) {
      if (scores[i][j] < scores[i - 1][j - 1]) {
        current[i - 1] = letters[i][j];
        path.push({
          current: current.slice(),
          type: 'replace',
          position: i,
          item: letters[i][j],
        });
      }
      i--;
      j--;
    } else if (sources[i][j] === config.sources.remove) {
      current.splice(i - 1, 1);
      path.push({
        current: current.slice(),
        type: 'delete',
        position: i,
        item: letters[i][j],
      });
      i--;
    } else if (sources[i][j] === config.sources.insert) {
      current.splice(i, 0, letters[i][j]);
      path.push({
        current: current.slice(),
        type: 'insert',
        position: i + 1,
        item: letters[i][j],
      });
      j--;
    }
  }
  return path;
}

var a = readline().trim();
var b = readline().trim();
var changes = main(a.split(''), b.split(''));

print(changes.length);
changes.forEach(function (change) {
  print(change.type.toUpperCase() + ' ' + change.position + (change.type === 'delete' ? '' : (' ' + change.item)));
});

function main(a, b) {
  // define variables
  var i, j;
  var config = {
    sources: {
      insert: 0,
      remove: 1,
      matching: 2
    },
    scores: {
      match: 0,
      replace: -1,
      insert: -1,
      remove: -1
    }
  };
  function create() {
    var table = [];
    for (var i = 0; i < a.length + 1; i++) {
      var row = [];
      for (var j = 0; j < b.length + 1; j++) {
        row.push(null);
      }
      table.push(row);
    }
    return table;
  }
  var scores = create();
  var sources = create();
  var letters = create();

  // compute first row and first column
  scores[0][0] = 0;
  for (i = 0; i < a.length; i++) {
    scores[i + 1][0] = (i + 1) * config.scores.remove;
    sources[i + 1][0] = config.sources.remove;
    letters[i + 1][0] = a[i];
  }
  for (i = 0; i < b.length; i++) {
    scores[0][i + 1] = (i + 1) * config.scores.insert;
    sources[0][i + 1] = config.sources.insert;
    letters[0][i + 1] = b[i];
  }

  // compute the whole table
  for (i = 1; i < scores.length; i++) {
    for (j = 1; j < scores[i].length; j++) {
      var match = a[i - 1] === b[j - 1];
      var insertScore = scores[i][j - 1] + config.scores.insert;
      var removeScore = scores[i - 1][j] + config.scores.remove;
      var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];

      if (insertScore >= removeScore && insertScore >= matchingScore) {
        scores[i][j] = insertScore;
        sources[i][j] = config.sources.insert;
        letters[i][j] = b[j - 1];
      } else if (removeScore >= insertScore && removeScore >= matchingScore) {
        scores[i][j] = removeScore;
        sources[i][j] = config.sources.remove;
        letters[i][j] = a[i - 1];
      } else if (matchingScore >= removeScore && matchingScore >= insertScore) {
        scores[i][j] = matchingScore;
        sources[i][j] = config.sources.matching;
        letters[i][j] = match ? null : {
          from: a[i - 1],
          to: b[j - 1]
        };
      }
    }
  }

  // return the editing operation list
  var operations = [];
  j = b.length;
  i = a.length;
  while (i > 0 || j > 0) {
    if (sources[i][j] === config.sources.matching) {
      if (scores[i][j] < scores[i - 1][j - 1]) {
        operations.push({
          type: 'replace',
          position: i,
          item: letters[i][j]
        });
      }
      i--;
      j--;
    } else if (sources[i][j] === config.sources.remove) {
      operations.push({
        type: 'delete',
        position: i,
        item: letters[i][j]
      });
      i--;
    } else if (sources[i][j] === config.sources.insert) {
      operations.push({
        type: 'insert',
        position: i + 1,
        item: letters[i][j]
      });
      j--;
    }
  }

  return operations;
}

var a = readline().trim();
var b = readline().trim();
var changes = main(a.split(''), b.split(''));

print(changes.length);
changes.forEach(function (change) {
  print(change.type.toUpperCase() + ' ' + change.position + (change.type === 'delete' ? '' : (' ' + (change.type === 'replace' ? change.item.to : change.item))));
});

var debug = false;

function main(a, b) {
  if (debug) {
    print(a);
    print(b);
  }

  // define variables
  var config = {
    sources: {
      insert: 'li',
      remove: 'ur',
      matching: 'dm',
    },
    scores: {
      match: 0,
      replace: -1,
      insert: -1,
      remove: -1
    },
  };
  function create() {
    var table = [];
    for (var i = 0; i < a.length + 1; i++) {
      var row = [];
      for (var j = 0; j < b.length + 1; j++) {
        row.push(null);
      }
      table.push(row);
    }
    return table;
  }
  function show(table) {
    if (!debug) {
      return;
    }
    write('     ');
    for (var i = 0; i < table[0].length - 1; i++) {
      write(b[i] + '  ');
    }
    write('\n');

    for (var i = 0; i < table.length; i++) {
      if (i > 0) {
        write(a[i - 1] + ' ');
      } else {
        write('  ');
      }
      for (var j = 0; j < table[i].length; j++) {
        write(table[i][j] + ' ');
      }
      write('\n');
    }
  }
  var scores = create();
  var sources = create();
  var letters = create();

  show(scores);

  // compute first row and first column
  scores[0][0] = 0;
  for (var i = 0; i < a.length; i++) {
    scores[i + 1][0] = (i + 1) * config.scores.remove;
    sources[i + 1][0] = config.sources.remove;
    letters[i + 1][0] = a[i];
  }
  for (var i = 0; i < b.length; i++) {
    scores[0][i + 1] = (i + 1) * config.scores.insert;
    sources[0][i + 1] = config.sources.insert;
    letters[0][i + 1] = b[i];
  }

  show(scores);

  // compute the whole table
  for (var i = 1; i < scores.length; i++) {
    for (var j = 1; j < scores[i].length; j++) {
      var match = a[i - 1] === b[j - 1];
      var insertScore = scores[i][j - 1] + config.scores.insert;
      var removeScore = scores[i - 1][j] + config.scores.remove;
      var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];

      if (insertScore >= removeScore && insertScore >= matchingScore) {
        scores[i][j] = insertScore;
        sources[i][j] = config.sources.insert;
        letters[i][j] = b[j - 1];
      } else if (removeScore >= insertScore && removeScore >= matchingScore) {
        scores[i][j] = removeScore;
        sources[i][j] = config.sources.remove;
        letters[i][j] = a[i - 1];
      } else if (matchingScore >= removeScore && matchingScore >= insertScore) {
        scores[i][j] = matchingScore;
        sources[i][j] = config.sources.matching;
        letters[i][j] = match ? ' ' : b[j - 1];
      }
    }
  }

  show(scores);
  show(sources);
  show(letters);

  var path = [];
  var j = b.length;
  var i = a.length;
  var current = a.slice();

  while (i > 0 || j > 0) {
    if (sources[i][j] === config.sources.matching) {
      if (scores[i][j] < scores[i - 1][j - 1]) {
        current[i - 1] = letters[i][j];
        path.push({
          current: current.slice(),
          type: 'replace',
          position: i,
          item: letters[i][j],
        });
      }
      i--;
      j--;
    } else if (sources[i][j] === config.sources.remove) {
      current.splice(i - 1, 1);
      path.push({
        current: current.slice(),
        type: 'delete',
        position: i,
        item: letters[i][j],
      });
      i--;
    } else if (sources[i][j] === config.sources.insert) {
      current.splice(i, 0, letters[i][j]);
      path.push({
        current: current.slice(),
        type: 'insert',
        position: i + 1,
        item: letters[i][j],
      });
      j--;
    }
  }

  return path;
}

var a = readline().trim();
var b = readline().trim();
/*
a = 'seven';
b = 'sved';
a = 'aba';
b = 'abbba';
a = 'accepted';
b = 'wronganswer';
*/
var changes = main(a.split(''), b.split(''));

if (debug) {
  print(a)
  print(b)
}
print(changes.length);
changes.forEach(function (change) {
  print(change.type.toUpperCase() + ' ' + change.position + (change.type === 'delete' ? '' : (' ' + change.item)));
  //print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item + ' (' + change.current.join('') + ')');
});

var debug = false;

function main(a, b) {
  if (debug) {
    print(a);
    print(b);
  }

  // define variables
  var config = {
    sources: {
      insert: 'li',
      remove: 'ur',
      matching: 'dm',
    },
    scores: {
      match: 0,
      replace: -1,
      insert: -1,
      remove: -1
    },
  };
  function create() {
    var table = [];
    for (var i = 0; i < a.length + 1; i++) {
      var row = [];
      for (var j = 0; j < b.length + 1; j++) {
        row.push(null);
      }
      table.push(row);
    }
    return table;
  }
  function show(table) {
    if (!debug) {
      return;
    }
    write('     ');
    for (var i = 0; i < table[0].length - 1; i++) {
      write(b[i] + '  ');
    }
    write('\n');

    for (var i = 0; i < table.length; i++) {
      if (i > 0) {
        write(a[i - 1] + ' ');
      } else {
        write('  ');
      }
      for (var j = 0; j < table[i].length; j++) {
        write(table[i][j] + ' ');
      }
      write('\n');
    }
  }
  var scores = create();
  var sources = create();
  var letters = create();

  show(scores);

  // compute first row and first column
  scores[0][0] = 0;
  for (var i = 0; i < a.length; i++) {
    scores[i + 1][0] = (i + 1) * config.scores.remove;
    sources[i + 1][0] = config.sources.remove;
    letters[i + 1][0] = a[i];
  }
  for (var i = 0; i < b.length; i++) {
    scores[0][i + 1] = (i + 1) * config.scores.insert;
    sources[0][i + 1] = config.sources.insert;
    letters[0][i + 1] = b[i];
  }

  show(scores);

  // compute the whole table
  for (var i = 1; i < scores.length; i++) {
    for (var j = 1; j < scores[i].length; j++) {
      var match = a[i - 1] === b[j - 1];
      var insertScore = scores[i][j - 1] + config.scores.insert;
      var removeScore = scores[i - 1][j] + config.scores.remove;
      var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];

      if (insertScore >= removeScore && insertScore >= matchingScore) {
        scores[i][j] = insertScore;
        sources[i][j] = config.sources.insert;
        letters[i][j] = b[j - 1];
      } else if (removeScore >= insertScore && removeScore >= matchingScore) {
        scores[i][j] = removeScore;
        sources[i][j] = config.sources.remove;
        letters[i][j] = a[i - 1];
      } else if (matchingScore >= removeScore && matchingScore >= insertScore) {
        scores[i][j] = matchingScore;
        sources[i][j] = config.sources.matching;
        letters[i][j] = match ? ' ' : b[j - 1];
      }
    }
  }

  show(scores);
  show(sources);
  show(letters);

  var path = [];
  var j = b.length;
  var i = a.length;
  var current = a.slice();

  while (i > 0 || j > 0) {
    if (sources[i][j] === config.sources.matching) {
      if (scores[i][j] < scores[i - 1][j - 1]) {
        current[i - 1] = letters[i][j];
        path.push({
          current: current.slice(),
          type: 'replace',
          position: i,
          item: letters[i][j],
        });
      }
      i--;
      j--;
    } else if (sources[i][j] === config.sources.remove) {
      current.splice(i - 1, 1);
      path.push({
        current: current.slice(),
        type: 'remove',
        position: i,
        item: letters[i][j],
      });
      i--;
    } else if (sources[i][j] === config.sources.insert) {
      current.splice(i, 0, letters[i][j]);
      path.push({
        current: current.slice(),
        type: 'insert',
        position: i + 1,
        item: letters[i][j],
      });
      j--;
    }
  }

  return path;
}

var a = readline().trim();
var b = readline().trim();
/*
a = 'seven';
b = 'sved';
a = 'aba';
b = 'abbba';
a = 'accepted';
b = 'wronganswer';
*/
var changes = main(a.split(''), b.split(''));

if (debug) {
  print(a)
  print(b)
}
print(changes.length);
changes.forEach(function (change) {
  print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item);
  //print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item + ' (' + change.current.join('') + ')');
});

var debug = false;

function main(a, b) {
  if (debug) {
    print(a);
    print(b);
  }

  // define variables
  var config = {
    sources: {
      insert: 'li',
      remove: 'ur',
      matching: 'dm',
    },
    scores: {
      match: 0,
      replace: -1,
      insert: -1,
      remove: -1
    },
  };
  function create() {
    var table = [];
    for (var i = 0; i < a.length + 1; i++) {
      var row = [];
      for (var j = 0; j < b.length + 1; j++) {
        row.push(null);
      }
      table.push(row);
    }
    return table;
  }
  function show(table) {
    if (!debug) {
      return;
    }
    write('     ');
    for (var i = 0; i < table[0].length - 1; i++) {
      write(b[i] + '  ');
    }
    write('\n');

    for (var i = 0; i < table.length; i++) {
      if (i > 0) {
        write(a[i - 1] + ' ');
      } else {
        write('  ');
      }
      for (var j = 0; j < table[i].length; j++) {
        write(table[i][j] + ' ');
      }
      write('\n');
    }
  }
  var scores = create();
  var sources = create();
  var letters = create();

  show(scores);

  // compute first row and first column
  scores[0][0] = 0;
  for (var i = 0; i < a.length; i++) {
    scores[i + 1][0] = (i + 1) * config.scores.remove;
    sources[i + 1][0] = config.sources.remove;
    letters[i + 1][0] = a[i];
  }
  for (var i = 0; i < b.length; i++) {
    scores[0][i + 1] = (i + 1) * config.scores.insert;
    sources[0][i + 1] = config.sources.insert;
    letters[0][i + 1] = b[i];
  }

  show(scores);

  // compute the whole table
  for (var i = 1; i < scores.length; i++) {
    for (var j = 1; j < scores[i].length; j++) {
      var match = a[i - 1] === b[j - 1];
      var insertScore = scores[i][j - 1] + config.scores.insert;
      var removeScore = scores[i - 1][j] + config.scores.remove;
      var matchingScore = scores[i - 1][j - 1] + config.scores[match ? 'match' : 'replace'];

      if (insertScore >= removeScore && insertScore >= matchingScore) {
        scores[i][j] = insertScore;
        sources[i][j] = config.sources.insert;
        letters[i][j] = b[j - 1];
      } else if (removeScore >= insertScore && removeScore >= matchingScore) {
        scores[i][j] = removeScore;
        sources[i][j] = config.sources.remove;
        letters[i][j] = a[i - 1];
      } else if (matchingScore >= removeScore && matchingScore >= insertScore) {
        scores[i][j] = matchingScore;
        sources[i][j] = config.sources.matching;
        letters[i][j] = match ? ' ' : b[j - 1];
      }
    }
  }

  show(scores);
  show(sources);
  show(letters);

  var path = [];
  var j = b.length;
  var i = a.length;
  var current = a.slice();

  while (i > 0 || j > 0) {
    if (sources[i][j] === config.sources.matching) {
      if (scores[i][j] < scores[i - 1][j - 1]) {
        current[i - 1] = letters[i][j];
        path.push({
          current: current.slice(),
          type: 'replace',
          position: i,
          item: letters[i][j],
        });
      }
      i--;
      j--;
    } else if (sources[i][j] === config.sources.remove) {
      current.splice(i - 1, 1);
      path.push({
        current: current.slice(),
        type: 'delete',
        position: i,
        item: letters[i][j],
      });
      i--;
    } else if (sources[i][j] === config.sources.insert) {
      current.splice(i, 0, letters[i][j]);
      path.push({
        current: current.slice(),
        type: 'insert',
        position: i + 1,
        item: letters[i][j],
      });
      j--;
    }
  }

  return path;
}

var a = readline().trim();
var b = readline().trim();
/*
a = 'seven';
b = 'sved';
a = 'aba';
b = 'abbba';
a = 'accepted';
b = 'wronganswer';
*/
var changes = main(a.split(''), b.split(''));

if (debug) {
  print(a)
  print(b)
}
print(changes.length);
changes.forEach(function (change) {
  print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item);
  //print(change.type.toUpperCase() + ' ' + change.position + ' ' + change.item + ' (' + change.current.join('') + ')');
});


Little X and Little Z are good friends. They always chat online. But both of them have schedules.Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). But the schedule of Little X is quite strange, it depends on the time when he gets up. If he gets up at time 0, he will be online at any moment of time between c1 and d1, between c2 and d2, ..., between cq and dq (all borders inclusive). But if he gets up at time t, these segments will be shifted by t. They become [ci + t, di + t] (for all i).If at a moment of time, both Little X and Little Z are online simultaneosly, they can chat online happily. You know that Little X can get up at an integer moment of time between l and r (both borders inclusive). Also you know that Little X wants to get up at the moment of time, that is suitable for chatting with Little Z (they must have at least one common moment of time in schedules). How many integer moments of time from the segment [l, r] suit for that?

The first line contains four space-separated integers p, q, l, r (1 ≤  p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000). Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000). It's guaranteed that bi < ai + 1 and dj < cj + 1 for all valid i and j.

Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.

;(function () {
	print(function (p, q, l, r) {
		var t = 0;

		var ab = [];
		while (p--) {
			ab.push(readline().split(' ').map(Number));
		} p = ab.length;

		var cd = [];
		while (q--) {
			cd.push(readline().split(' ').map(Number));
		} q = cd.length;

		for (; l <= r; l++) {
			var w = true;
			for (var i = 0; i < p && w; i++) {
				for (var j = 0; j < q && w; j++) {
					var a = ab[i], b = [cd[j][0] + l, cd[j][1] + l];

					if (Math.max(a[1], b[1]) >= Math.min(a[0], b[0]) && Math.min(a[1], b[1]) >= Math.max(a[0], b[0]) ) {
						t++;
						w = false;
					}
				}
			}
		}

		return t;
	}.apply(null, readline().split(' ').map(Number)));
}.call(this));

function ProblemSolver() {

    this.solveCase = function() {
        var res , i , j , a , b , c , d , e  , k;
        res = 0;
        for( i = 0 ; i < this.p ; i++ ) {
            a = this.arr[ i ];
            b = this.brr[ i ];
            for( j = a ; j <= b ; j++ ) {
                this.err[ j ] = 1;
            }
        }
        for( i = this.l ; i <= this.r ; i++ ) {
            c = 0 ;
            for( j = 0 ; j < this.q ; j++ ) {
                a = this.crr[ j ] + i;
                b = this.drr[ j ] + i;
                for( k = a ; k <= b ; k++ ) {
                    if( this.err[ k ] == 1 ) {
                        c = 1 ;
                        break ;
                    }
                }
            }
            if( c == 1 ) {
                res++ ;
            }
        }
        print( res );
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.p = irObj.nextInt();
            this.q = irObj.nextInt();
            this.l = irObj.nextInt();
            this.r = irObj.nextInt();
            for( i = 0 ; i < this.p ; i++ ) {
                this.arr[ i ] = irObj.nextInt();
                this.brr[ i ] = irObj.nextInt();
            }
            for( i = 0 ; i < this.q ; i++ ) {
                this.crr[ i ] = irObj.nextInt();
                this.drr[ i ] = irObj.nextInt();
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.brr = new Array();
        this.crr = new Array();
        this.drr = new Array();
        this.err = new Array();
        this.frr = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.crr.push( 0 );
            this.drr.push( 0 );
            this.err.push( 0 );
            this.frr.push( 0 );
            this.adj_list.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        //this.clearArraysPerCase() ;
    };

    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.crr = new Array();
        this.drr = new Array();
        this.err = new Array();
        this.frr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.crr.push( 0 );
            this.drr.push( 0 );
            this.err.push( 0 );
            this.frr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init = function() {
        this.lim1 = 1010;
        this.lim2 = 110;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.memsetArray1D = function( arrParam , val ) {
        var i;
        if( arrParam == null ) {
            throw new Error( "No array supplied in the parameter!" );
        }
        if( val == null ) {
            throw new Error( "No value for memset has been supplied in the parameter!" );
        }
        arrParam = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            arrParam.push( val );
        }
        return arrParam;
    };

    this.getStringLength = function( stringData ) {
        var len , lengthType;
        len = stringData.length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = stringData.length();
        }
        else {
            len = stringData.length;
        }
        return len;
    };

    this.init();
}

function InputReader() {
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhinoStdin = function() {
        importPackage( java.io );
        importPackage( java.lang );
        var singleLine , reader;
        reader = new BufferedReader( new InputStreamReader( System[ "in" ] ) );
        this.allLines = [];
        while( true ) {
            singleLine = reader.readLine();
            if( singleLine != null ) {
                this.allLines.push( singleLine );
            }
            else {
                break;
            }
        }
    };

    this.readAllLinesFromNodeStdin = function() {
        var fsObj , size , rawData;
        process.stdin.setEncoding( 'ascii' );
        fsObj = require( 'fs' );
        size = fsObj.fstatSync( process.stdin.fd ).size;
        rawData = fsObj.readSync( process.stdin.fd , size )[ 0 ];
        this.parseRawData( rawData );
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx , lengthType;
        len = this.allLines[ this.currrentLineNumber ].length;
        lengthType = typeof len;
        if( lengthType == "function" ) {
            len = this.allLines[ this.currrentLineNumber ].length();
        }
        if( flag == 0 ) {
            res = "";
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != '\t'.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = -1;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) || this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == '\t'.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                res += String.fromCharCode( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) );
            }
            if( endIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            else {
                this.currrentCharacterIndex = endIdx;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        if( currentDirectory.charAt( 1 ) != ":" ) {
            //not local machine/windows
            outputFilePath = outputFileName;
        }
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCode = function() {
        var testCases , i , hasMoreTestCases , isLocalMachine , localContext;
        isLocalMachine = false;
        try {
            if( __dirname != null && __dirname.charAt( 1 ) == ':' ) {
                //only on windows
                isLocalMachine = true;
            }
        }
        catch( ex ) {
            isLocalMachine = false;
        }
        if( isLocalMachine == true ) {
            //local machine runs on node and relies on file i/o
            print = console.log;
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
        }
        else {
            //server machine
            try {
                var rlObj = readline;
                //server runs on javasctipt v8 distribution and has readline method on global context
                this.irObj.readAllLines();
            }
            catch( ex ) {
                try {
                    var pObj = process;
                    //server runs on node
                    print = console.log;
                    this.irObj.readAllLinesFromNodeStdin();
                }
                catch( ex ) {
                    try {
                        var ipObj = importPackage;
                        //server runs on rhino
                        this.irObj.readAllLinesFromRhinoStdin();
                    }
                    catch( ex ) {
                        throw new Error( "Unknown javasctipt distribution!" );
                    }
                }
            }
        }
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            //only works for local machine(tested)
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.runCode();
}

new CodeExecutioner();

var p = readline().split(/\s/gi).map(Number),
			q = p[1], l = p[2], r = p[3], p = p[0],
			abArr = [ [ -1, -1 ] ], cdArr = [ [ -1, -1 ] ], result = {};

		for(var i = 1; i <= p; i++)	{
			var ab = readline().split(/\s/gi).map(Number),
				a = ab[0], b = ab[1];

			if(abArr[abArr.length - 1][1] < a)	abArr.push(ab);
		}

		for(var j = 1; j <= q; j++)	{
			var cd = readline().split(/\s/gi).map(Number),
				c = cd[0], d = cd[1];

			if(cdArr[cdArr.length - 1][1] < c)	{
				cdArr.push(cd);

				for(var k = 1; k <= abArr.length - 1; k++)	{
					var a = abArr[k][0], b = abArr[k][1],
						sl = a - d, sr = b - c;

					sr > r ? sr = r : true;
					sl < l ? sl = l : true;

					if(sl >= l)	{
						//console.log('%d, %d', sl, sr);
						for(var n = sl; n <= sr; n++)	{
							result[n] = 1;
						}
					}
				}
			}
		}

		print(Object.keys(result).length);

var p = readline().split(/\s/gi).map(Number),
			q = p[1], l = p[2], r = p[3], p = p[0],
			abArr = [ [ -1, -1 ] ], cdArr = [ [ -1, -1 ] ], result = {};

		for(var i = 1; i <= p; i++)	{
			var ab = readline().split(/\s/gi).map(Number),
				a = ab[0], b = ab[1];

			if(abArr[abArr.length - 1][1] < a)	abArr.push(ab);
		}

		for(var i = 1; i <= q; i++)	{
			var cd = readline().split(/\s/gi).map(Number),
				c = cd[0], d = cd[1];

			if(cdArr[cdArr.length - 1][1] < c)	{
				cdArr.push(cd);

				for(var k = 1; k <= p; k++)	{
					var a = abArr[k][0], b = abArr[k][1],
						sl = a - d, sr = b - c;

					sr > r ? sr = r : true;
					sl < 0 ? sl = 0 : true;

					if(sl >= 0)	{
						//console.log('%d, %d', sl, sr);
						for(var n = sl; n <= sr; n++)	{
							result[n] = 1;
						}
					}
				}
			}
		}

		print(Object.keys(result).length);

var p = readline().split(/\s/gi).map(Number),
			q = p[1], l = p[2], r = p[3], p = p[0],
			abArr = [ [ -1, -1 ] ], cdArr = [ [ -1, -1 ] ], result = {};

		for(var i = 1; i <= p; i++)	abArr.push(readline().split(/\s/gi).map(Number));
		for(var i = 1; i <= q; i++)	{
			var cd = readline().split(/\s/gi).map(Number),
				c = cd[0], d = cd[1];

			if(cdArr[cdArr.length - 1][1] < c)	{
				for(var k = 1; k <= p; k++)	{
					var a = abArr[k][0], b = abArr[k][1],
						sl = a - d, sr = b - c;

					sr > r ? sr = r : true;
					sl < 0 ? sl = 0 : true;

					if(sl >= 0)	{
						//console.log('%d, %d', sl, sr);
						for(var n = sl; n <= sr; n++)	{
							result[n] = 1;
						}
					}
				}
			}
		}

		print(Object.keys(result).length);

var p = readline().split(/\s/gi).map(Number),
			q = p[1], l = p[2], r = p[3], p = p[0],
			abArr = [ [ -1, -1 ] ], cdArr = [ [ -1, -1 ] ], result = {};

		for(var i = 1; i <= p; i++)	{
			var ab = readline().split(/\s/gi).map(Number),
				a = ab[0], b = ab[1];

			if(abArr[abArr.length - 1][1] < a)	abArr.push(ab);
		}

		for(var j = 1; j <= q; j++)	{
			var cd = readline().split(/\s/gi).map(Number),
				c = cd[0], d = cd[1];

			if(cdArr[cdArr.length - 1][1] < c)	{
				cdArr.push(cd);

				for(var k = 1; k <= abArr.length - 1; k++)	{
					var a = abArr[k][0], b = abArr[k][1],
						sl = a - d, sr = b - c;

					sr > r ? sr = r : true;
					sl < 0 ? sl = 0 : true;

					if(sl >= 0)	{
						//console.log('%d, %d', sl, sr);
						for(var n = sl; n <= sr; n++)	{
							result[n] = 1;
						}
					}
				}
			}
		}

		print(Object.keys(result).length);


The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of $$$n$$$ characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly $$$0$$$) on this string, partitioning it into several contiguous pieces, each with length at least $$$1$$$. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!For a string we define a ratio as $$$a:b$$$ where 'D' appears in it $$$a$$$ times, and 'K' appears $$$b$$$ times. Note that $$$a$$$ or $$$b$$$ can equal $$$0$$$, but not both. Ratios $$$a:b$$$ and $$$c:d$$$ are considered equal if and only if $$$a\cdot d = b\cdot c$$$. For example, for the string 'DDD' the ratio will be $$$3:0$$$, for 'DKD' — $$$2:1$$$, for 'DKK' — $$$1:2$$$, and for 'KKKKDD' — $$$2:4$$$. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$) — the length of the wood. The second line of each test case contains a string $$$s$$$ of length $$$n$$$. Every character of $$$s$$$ will be either 'D' or 'K'. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.

For each test case, output $$$n$$$ space separated integers. The $$$i$$$-th of these numbers should equal the answer for the prefix $$$s_{1},s_{2},\dots,s_{i}$$$.

NoteFor the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.For the second test case, you can split each prefix of length $$$i$$$ into $$$i$$$ blocks 'D'.

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.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const gcd = (a, b) => b ? gcd(b, a % b) : a;

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

		const ans = [];
		const m = new Map();
		for (let i = 0, d = 0, k = 0; i < n; i++) {
			d += s[i] == 'D';
			k += s[i] == 'K';

			const ratio = d / gcd(d, k) + ':' + k / gcd(d, k);
			ans[i] = 1 + (m.get(ratio) || 0);
			m.set(ratio, ans[i]);
		}

		console.log(ans.join(' '));
	}
}

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.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

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

		const ans = [];
		const mp = new Map();
		for (let i = 0, cnt = 0; i < n; i++) {
			cnt += s[i] == 'D';

			const cur = mp.get(cnt/(i+1)) || 1;
			ans[i] = cur;
			mp.set(cnt/(i+1), cur + 1);
		}

		console.log(ans.join(' '));
	}
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function div(a, b) {
   return Math.floor(a / b);
}

function solve() {
   var n = Number(read());
   var str = read();
   var dcount = [0];
   var kcount = [0];
   var save = new Map();
   for(var i = 0; i < n; i++) {
      if (str[i] === 'D') {
         dcount.push(dcount[i] + 1);
         kcount.push(kcount[i]);
         continue;
      }
      dcount.push(dcount[i]);
      kcount.push(kcount[i] + 1);
   }
   var ans = [];
   for (var i = 1; i <= n; i++) {
      if (dcount[i] === 0 || kcount[i] === 0) {
         ans.push(dcount[i] + kcount[i]);
         continue;
      }
      var countGcd = gcd(dcount[i], kcount[i]);
      var strSave = div(dcount[i], countGcd) + ':' + div(kcount[i], countGcd);
      if (countGcd === 1) {
         ans.push(1);
         save.set(strSave, 1);
         continue;
      }
      if (save.has(strSave)) {
         var curAns = save.get(strSave) + 1;
         ans.push(curAns);
         save.set(strSave, curAns);
         continue;
      }
      ans.push(1);
      save.set(strSave, 1);
   }
   write(ans.join(' '));
}

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

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

function readArray(f) {
   return read().split(' ').map(f);
}

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function div(a, b) {
   return Math.floor(a / b);
}

function solve() {
   var n = Number(read());
   var str = read();
   var dcount = [0];
   var kcount = [0];
   var save = {};
   for(var i = 0; i < n; i++) {
      if (str[i] === 'D') {
         dcount.push(dcount[i] + 1);
         kcount.push(kcount[i]);
         continue;
      }
      dcount.push(dcount[i]);
      kcount.push(kcount[i] + 1);
   }
   var ans = [];
   for (var i = 1; i <= n; i++) {
      if (dcount[i] === 0 || kcount[i] === 0) {
         ans.push(dcount[i] + kcount[i]);
         continue;
      }
      var countGcd = gcd(dcount[i], kcount[i]);
      var strSave = div(dcount[i], countGcd) + ':' + div(kcount[i], countGcd);
      if (countGcd === 1) {
         ans.push(1);
         save[strSave] = 1;
         continue;
      }
      if (save[strSave]) {
         var curAns = save[strSave] + 1;
         ans.push(curAns);
         save[strSave] = curAns;
         continue;
      }
      ans.push(1);
      save[strSave] = 1;
   }
   write(ans.join(' '));
}

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

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

function readArray(f) {
   return read().split(' ').map(f);
}

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

'use strict';

function solve(n, s) {
  const map = new Map();
  const dp = [];
  let d = 0,
      k = 0;
  for (let i = 0; i < n; i++) {
    if (s[i] === 'D') d++;else k++;
    const a = gcd(d, k),
          b = d / a,
          c = k / a,
          r = `${b},${c}`;
    if (map.has(r)) {
      dp[i] = dp[map.get(r)] + 1;
    } else {
      dp[i] = 1;
    }
    map.set(r, i);
  }
  return dp.join(' ');
}
function gcd(a, b) {
  return !b ? a : gcd(b, a % b);
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = await read();
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

function key(a, b) {
  return a + ',' + b;
}
function gcd( a,  b)
{
    /* GCD(0, b) == b; GCD(a, 0) == a,
       GCD(0, 0) == 0 */
    if (a == 0)
        return b;
    if (b == 0)
        return a;

    /*Finding K, where K is the
      greatest power of 2
      that divides both a and b. */
    var k;
    for (k = 0; ((a | b) & 1) == 0; ++k)
    {
        a >>= 1;
        b >>= 1;
    }

    /* Dividing a by 2 until a becomes odd */
    while ((a & 1) == 0)
        a >>= 1;

    /* From here on, 'a' is always odd. */
    do
    {
        /* If b is even, remove all factor of 2 in b */
        while ((b & 1) == 0)
            b >>= 1;

        /* Now a and b are both odd.
           Swap if necessary so a <= b,
           then set b = b - a (which is even).*/
        if (a > b){
        var t = a;
        a = b;
        b = t;
        }

        b = (b - a);
    } while (b != 0);

    /* restore common factors of 2 */
    return a << k;
}

function woodSplits(str) {
  var dilucCount = 0;
  var kayeaCount = 0;
  var countsMap = {};
  var answer = [];
  for (var i = 0; i < str.length; i++) {
    if (str[i] == 'D') {
      dilucCount++;
    } else if (str[i] == 'K') {
      kayeaCount++;
    }
    var currentGcd = gcd(dilucCount, kayeaCount);
    var currentKey = key(dilucCount / currentGcd, kayeaCount / currentGcd);
    var newValue = 1 + (countsMap[currentKey] || 0);
    countsMap[currentKey] = newValue;
    answer.push(newValue);
  }
  return answer;
}

var numCases = Number(readline());
for (var i = 0; i < numCases; i++) {
  readline();
  var str = readline();
  print(woodSplits(str).join(' '));
}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var len = +readline();
    var tree = readline();
    var ds = 0;
    var ks = 0;
    var mp = {};
    var results = [];
    for (var j = 0; j < len; j++) {
      tree[j] === 'D' ? ds++ : ks++;
      var key = `d${ds/nod(ds, ks)}k${ks/nod(ds, ks)}`;
      mp[key] = mp[key] ? ++mp[key] : 1;
      results.push(mp[key]);
    }
    print(results.join(' '));
  }
}

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

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.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const mxN = 5e5 + 100;

const fact = Array.from(Array(mxN+1), x => []);

function computeFactors () {
	for (let i = 1; i <= mxN; i++) {
		let j = i;
		while (j <= mxN) {
			fact[j].push(i);
			j += i;
		}
	}
}

function main () {
	computeFactors();
	//console.log(fact[10], fact[100]);
	let T = rn();
	while (T--) {
		const n = rn();
		const s = rl();

		const dp = [];
		const cnt = []; cnt[-1] = 0;
		const ans = [];
		for (let i = 0; i < n; i++) {
			cnt[i] = cnt[i-1] + (s[i] == 'D');
			//console.log({cnt})
			for (const f of fact[i+1]) {
				const dCnt = cnt[i] - cnt[i-f];
				const ration = dCnt / f;
				//console.log({i, f, dCnt, ration})
				if (ration == dp[i-f]) {
					dp[i] = ration;
					ans[i] = ans[i-f]+1;
					break;
				}
				if (f == i+1) {
					dp[i] = ration;
					ans[i] = 1;
				}
			}
			//console.log({cnt});
		}

		console.log(ans.join(' '));
	}
}

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.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const mxN = 5e5 + 100;

const fact = Array.from(Array(mxN+1), x => []);

function computeFactors () {
	for (let i = 1; i <= mxN; i++) {
		let j = i;
		while (j <= mxN) {
			fact[j].push(i);
			j += i;
		}
	}
}

function main () {
	computeFactors();
	//console.log(fact[10], fact[100]);
	let T = rn();
	while (T--) {
		const n = rn();
		const s = rl();

		const dp = [];
		const cnt = []; cnt[-1] = 0;
		const ans = [];
		for (let i = 0; i < n; i++) {
			cnt[i] = cnt[i-1] + (s[i] == 'D');
			//console.log({cnt})
			for (const f of fact[i+1]) {
				const dCnt = cnt[i] - cnt[i-f];
				const ration = dCnt / f;
				//console.log({i, f, dCnt, ration})
				if (ration == dp[i-f] && ans[i-f] == (i-f+1)/f) {
					dp[i] = ration;
					ans[i] = (i+1)/f;
					break;
				}
				if (f == i+1) {
					dp[i] = ration;
					ans[i] = 1;
				}
			}
			//console.log({cnt});
		}
			//console.log({dp});

		console.log(ans.join(' '));
	}
}

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.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const mxN = 5e5 + 100;

const fact = Array.from(Array(mxN+1), x => []);

function computeFactors () {
	for (let i = 1; i <= mxN; i++) {
		let j = i;
		while (j <= mxN) {
			fact[j].push(i);
			j += i;
		}
	}
}

function main () {
	computeFactors();
	//console.log(fact[10], fact[100]);
	let T = rn();
	while (T--) {
		const n = rn();
		const s = rl();

		const dp = [];
		const cnt = []; cnt[-1] = 0;
		const ans = [];
		for (let i = 0; i < n; i++) {
			cnt[i] = cnt[i-1] + (s[i] == 'D');
			//console.log({cnt})
			for (const f of fact[i+1]) {
				const dCnt = cnt[i] - cnt[i-f];
				const ration = dCnt / f;
				//console.log({i, f, dCnt, ration})
				if (ration == dp[i-f] || f == i+1) {
					dp[i] = ration;
					ans[i] = (i+1)/f;
					break;
				}
			}
			//console.log({dp});
			//console.log({cnt});
		}

		console.log(ans.join(' '));
	}
}

var cache = {};
function key(a, b) {
  return a + ',' + b;
}
// https://en.wikipedia.org/wiki/Greatest_common_divisor
function gcd(a, b){
  if(key(a, b) in cache) return cache[key(a, b)];

  var result = b === 0 ? a : gcd(b, a % b);
  cache[key(a, b)] = result;
  return result;
}

function woodSplits(str) {
  var dilucCount = 0;
  var kayeaCount = 0;
  var countsMap = {};
  var answer = [];
  for (var i = 0; i < str.length; i++) {
    if (str[i] == 'D') {
      dilucCount++;
    } else if (str[i] == 'K') {
      kayeaCount++;
    }
    var currentGcd = gcd(dilucCount, kayeaCount);
    var currentKey = key(dilucCount / currentGcd, kayeaCount / currentGcd);
    var newValue = 1 + (countsMap[currentKey] || 0);
    countsMap[currentKey] = newValue;
    answer.push(newValue);
  }
  return answer;
}

var numCases = Number(readline());
for (var i = 0; i < numCases; i++) {
  readline();
  var str = readline();
  print(woodSplits(str));
}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var len = +readline();
    var tree = readline();
    var ds = 0;
    var ks = 0;
    var results = [];
    for (var j = 0; j < len; j++) {
      tree[j] === 'D' ? ds++ : ks++;
      var max = ds > ks ? ds : ks;
      var min = ds < ks ? ds : ks;
      if (min === 0) {
        results.push(max);
      } else if (max % min === 0) {
        results.push(min)
      } else { results.push(1) }
    }
    print(results.join(' '));
  }
}

main();