You are given a binary string $$$s$$$ of length $$$n$$$.Let's define $$$d_i$$$ as the number whose decimal representation is $$$s_i s_{i+1}$$$ (possibly, with a leading zero). We define $$$f(s)$$$ to be the sum of all the valid $$$d_i$$$. In other words, $$$f(s) = \sum\limits_{i=1}^{n-1} d_i$$$.For example, for the string $$$s = 1011$$$:   $$$d_1 = 10$$$ (ten);  $$$d_2 = 01$$$ (one)  $$$d_3 = 11$$$ (eleven);  $$$f(s) = 10 + 01 + 11 = 22$$$. In one operation you can swap any two adjacent elements of the string. Find the minimum value of $$$f(s)$$$ that can be achieved if at most $$$k$$$ operations are allowed.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. First line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^5$$$, $$$0 \le k \le 10^9$$$) — the length of the string and the maximum number of operations allowed. The second line of each test case contains the binary string $$$s$$$ of length $$$n$$$, consisting of only zeros and ones. It is also given that sum of $$$n$$$ over all the test cases doesn't exceed $$$10^5$$$.

For each test case, print the minimum value of $$$f(s)$$$ you can obtain with at most $$$k$$$ operations.

Note  For the first example, you can't do any operation so the optimal string is $$$s$$$ itself. $$$f(s) = f(1010) = 10 + 01 + 10 = 21$$$.  For the second example, one of the optimal strings you can obtain is "0011000". The string has an $$$f$$$ value of $$$22$$$.  For the third example, one of the optimal strings you can obtain is "00011". The string has an $$$f$$$ value of $$$12$$$.

'use strict';

function solve(n, m, s) {
  const nums = s.split('').map(str => Number(str));
  let t = n;
  if (nums[n - 1] === 0) {
    for (let i = n - 1; i >= 0; i--) {
      if (nums[i]) {
        if (n - i - 1 <= m) {
          m -= n - i - 1;
          nums[i] = 0;
          nums[n - 1] = 1;
          t = i + 1;
        }
        break;
      }
    }
  }
  if (nums[0] === 0) {
    for (let i = 0; i < Math.min(m + 1, t - 1); i++) {
      if (nums[i]) {
        nums[i] = 0;
        nums[0] = 1;
        break;
      }
    }
  }
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += nums[i - 1] * 10 + nums[i];
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n, k] = ra();
  let s = readline();
  LT({n, k, s});
  // PROCESSING:
  let sum = 0;
  let lastPos = -1;
  let firstPos = -1;
  for (let i=0; i<n; i++){
    if (s[i]=='0') continue;
    if (i<n-1)
      sum += 10;
    if (i>0)
      sum += 1;
    lastPos = i;
    if (firstPos==-1)
      firstPos = i;
  }
  L({lastPos, n, k})
  let taken = false;
  if (lastPos<n-1 && lastPos>=0 && n-1-lastPos<=k){
    sum -= 10;
    k-= n-lastPos-1;
    taken = true;
    if (lastPos==0)
      sum += 1;
  }
  if ((firstPos!=lastPos || !taken) && firstPos>0 && firstPos<=k && firstPos<n-1){
    sum--;
  }
  return sum;
};

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);
  const results = [];
  for (let tc = 0; tc < T; tc++) {
    const [N, K] = input.next().value.split(" ").map(Number);
    let S = input.next().value.split("");
    let life = K;
    let sum = 0;
    for (let i = 1; i < N - 1; i++) {
      if (S[i] === "1") sum += 11;
    }

    let zeroPadRight = 0;
    for (let i = N - 1; i > 0; i--) {
      if (S[i] === "0") zeroPadRight += 1;
      else break;
    }
    if (zeroPadRight === N - 1) zeroPadRight = 0;

    if (S[N - 1] === "1") sum += 1;
    else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {
      sum -= 10;
      life -= zeroPadRight;
      S[N - 1] = "1";
      S[N - 1 - zeroPadRight] = "0";
    }

    let zeroPadLeft = 0;
    for (let i = 0; i < N - 1; i++) {
      if (S[i] === "0") zeroPadLeft += 1;
      else break;
    }
    if (zeroPadLeft === N - 1) zeroPadLeft = 0;

    if (S[0] === "1") sum += 10;
    else if (life > 0 && zeroPadLeft > 0 && life >= zeroPadLeft) {
      sum -= 1;
    }

    if (S[0] === "1" && S[N - 1] === "0" && life >= N - 1) {
      sum -= 9;
    }

    results.push(sum);
  }
  console.log(results.join("\n"));
}

/**
 * Format:
 * {type: 'number', namedVariable?: string }
 * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }
 * {type: 'array', namedVariable?: string }
 * {type: 'string', namedVariable?: string }
 */
const readline = require('readline');

function createCLIReader(instructions) {
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });
  const mappedVariables = {};

  let resolvePromise = null;
  const donePromise = new Promise((res, rej) => {
    resolvePromise = res;
  });

  function waitUntilDone() {
    return donePromise;
  }

  /**
   * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }
   */
  const stack = [];
  let pc = -1;

  function finished() {
    if (pc >= instructions.length) {
      return true;
    }
    return false;
  }

  function checkFinished() {
    // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);
    if (pc >= instructions.length) {
      return true;
    }
    if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {
      return true;
    }
    return false;
  }

  function getNextInstructionContext() {
    if (!stack.length) {
      return {
        index: ++pc,
      }
    }
    const lastStack = stack[stack.length - 1];
    if (lastStack.pointer === lastStack.instructionCount) {
      lastStack.pointer = 0;
      lastStack.iteration = lastStack.iteration + 1;
    }
    if (lastStack.count === lastStack.iteration) {
      stack.pop();
      pc = lastStack.basePointer + lastStack.instructionCount + 1;
      return {
        index: pc,
      }
    }

    lastStack.pointer = lastStack.pointer + 1;
    return {
      index: lastStack.basePointer + lastStack.pointer,
      context: {
        namedPath: [...lastStack.context.namedPath, lastStack.iteration]
      }
    }
  }

  function pushRepeatToStack(instruction, index, context) {
    stack.push({
      type: 'repeat',
      count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],
      iteration: 0,
      basePointer: index,
      pointer: 0,
      instructionCount: instruction.instructionCount,
      context: {
        namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],
      }
    })
    setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);
  }

  function nextInstruction() {
    if (finished()) {
      // console.warn('Calling nextInstruction after finished, something is wrong');
      return;
    }
    while (true) {
      const { index, context } = getNextInstructionContext();
      const instruction = instructions[index];

      // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);
      switch (instruction.type) {
        case 'number':
        case 'array':
        case 'string':
          return {
            ...instruction,
            namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,
          }
        case 'repeat':
          pushRepeatToStack(instruction, index, context);
          break;
        default:
          // console.warn('Unclear instruction, abort');
          return;
      }
    }
  }

  function getIn(object, path) {
    for (let i = 0; i < path.length; ++i) {
      object = object[path[i]];
    }
    return object;
  }

  function setIn(object, path, value) {
    for (let i = 0; i < path.length - 1; ++i) {
      if (object[path[i]] == null) {
        object[path[i]] = {};
      }
      object = object[path[i]];
    }
    object[path[path.length - 1]] = value;
  }

  rl.on('line', line => {
    if (finished()) {
      return;
    }
    const { type, namedPath } = nextInstruction();
    switch (type) {
      case 'number':
        if (namedPath) {
          setIn(mappedVariables, namedPath, parseInt(line));
        }
        break;
      case 'string':
        if (namedPath) {
          setIn(mappedVariables, namedPath, line.trim());
        }
        break;
      case 'array':
        if (namedPath) {
          setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));
        }
        break;
      default:
      // console.warn(`Value unread, received type ${type}.`);
    }

    if (checkFinished()) {
      resolvePromise(mappedVariables);
      rl.close();
    }
  });
  return {
    waitUntilDone,
  };
}

function solve(testCase) {
  let k = testCase.lengthAndPermit[1];

  let oneCount = 0;
  let firstOne = -1;
  let lastOne = -1;
  for (let i = 0; i < testCase.theInput.length; ++i) {
    if (testCase.theInput[i] === '1') {
      if (firstOne === -1) {
        firstOne = i;
      }
      lastOne = i;
      ++oneCount;
    }
  }

  if (oneCount === 0) {
    return 0;
  }

  if (oneCount === testCase.theInput.length) {
    return 11 * (oneCount - 1);
  }

  let preliminarySum = 11 * oneCount;
  const distanceToLast = testCase.theInput.length - 1 - lastOne;
  const distanceToFirst = firstOne;

  let usedOne = false;
  if (k - distanceToLast >= 0) {
    k -= distanceToLast;
    preliminarySum -= 10;
    usedOne = true;
  }
  if (k - distanceToFirst >= 0 && (oneCount > 1 || !usedOne)) {
    preliminarySum -= 1;
  }

  return preliminarySum;
}

(async function main() {
  const reader = createCLIReader([
    { type: 'number', namedVariable: 'numberOfTestCase' },
    { type: 'repeat', instructionCount: 2, count: 'numberOfTestCase', namedVariable: 'testCase' },
    { type: 'array', namedVariable: 'lengthAndPermit' },
    { type: 'string', namedVariable: 'theInput' }
  ]);
  const schema = await reader.waitUntilDone();

  for (let i = 0; i < schema.numberOfTestCase; ++i) {
    console.log(solve(schema.testCase[i]));
  }
})();

class Scaner {
    data = [];
    constructor() {
        process.stdin.setEncoding('utf-8');
        process.stdin.on('data', _data => {
            let lasttext = this.data.pop();
            if (lasttext == undefined)
                lasttext = ""
            _data = lasttext + _data;
            const l = _data.split('\n');
            this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);
        });
    }
    read = async () => {
        process.stdin.resume();
        while (this.data.length < 2) {
            await delay(0);
        }
        process.stdin.pause();
        let res = this.data.shift();
        if (res == "")
            return await read();
        return res;
    };
}
const delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));
const print = (text) => process.stdout.write("" + text);
const scaner = new Scaner()
const read = scaner.read;
//----------------------------------------------------------------
//-----------------------the-code---------------------------------
//----------------------------------------------------------------

(async () => {
    let t = parseInt(await read());
    while (t--) {
        let [n,k]=(await read()).split(' ').map(Number);
        let a=await read();
        let ans=0;
        let i,j;
        for (i = a.length-1; i >= 0; i--){
            const e = a[i];
            if(e=='1'){
                const cost=a.length-i-1;
                if(cost<=k){
                    k-=cost;
                    ans+=1;
                }else{
                    i++;
                }
                break;
            }
        }
        for (j = 0; j < i; j++){
            const e = a[j];
            if(e=='1'){
                const cost=j;
                if(cost<=k){
                    k-=cost;
                    ans+=10;
                }else{
                    ans+=11;
                }
                break;

            }
        }
        for (j++; j < i; j++){
            if(a[j]=='1'){
                ans+=11;
            }
        }
        console.log(ans);
    }
})().then(() => { }
)

function solve() {
   let [n, k] = readArray(Number);
   const bitStr = read();
   let countOne = 0;
   let firstOne = n;
   let lastOne = -1;
   for (let i = 0; i < n; i++) {
      if (bitStr[i] === '0') {
         continue;
      }
      countOne++;
      if (i > lastOne) {
         lastOne = i;
      }
      if (i < firstOne) {
         firstOne = i;
      }
   }
   if (countOne === 0) {
      write(0);
      return;
   }
   const leftSwaps = firstOne;
   const rigthSwaps = n - lastOne - 1;
   if (countOne === 1) {
      if (rigthSwaps <= k) {
         write(1);
         return;
      }
      if (leftSwaps <= k) {
         write(10);
         return;
      }
      write(11);
      return;
   }
   let ans = countOne * 11;;
   if (rigthSwaps <= k) {
      k -= rigthSwaps;
      ans -= 10;
   }
   if (leftSwaps <= k) {
      ans -= 1;
   }
   write(ans);
}

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

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

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

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

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, m, s) {
  const nums = s.split('').map(str => Number(str));
  let t = n;
  if (nums[n - 1] === 0) {
    for (let i = n - 1; i >= 0; i--) {
      if (nums[i]) {
        if (n - i - 1 <= m) {
          m -= n - i - 1;
          nums[i] = 0;
          nums[n - 1] = 1;
          t = i + 1;
        }
        break;
      }
    }
  }
  if (nums[0] === 0) {
    for (let i = 0; i < Math.min(m + 1, t - 1); i++) {
      if (nums[i]) {
        nums[i] = 0;
        nums[0] = 1;
      }
    }
  }
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += nums[i - 1] * 10 + nums[i];
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    const t1=t
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      if(t1===243&&t1-t===69){
          console.log(`${m} ${n} ${s}`)
          return
      }
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';

function solve(n, m, s) {
  const nums = s.split('').map(str => Number(str));
  let t = n;
  if (nums[n - 1] === 0) {
    for (let i = n - 1; i >= 0; i--) {
      if (nums[i]) {
        if (n - i - 1 <= m) {
          m -= n - i - 1;
          nums[i] = 0;
          nums[n - 1] = 1;
          t = i + 1;
        }
        break;
      }
    }
  }
  if (nums[0] === 0) {
    for (let i = 0; i < Math.min(m + 1, t - 1); i++) {
      if (nums[i]) {
        nums[i] = 0;
        nums[0] = 1;
      }
    }
  }
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += nums[i - 1] * 10 + nums[i];
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    const t1=t
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      if(t===243&&t1-t===69){
          console.log(`${m} ${n} ${s}`)
          return
      }
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';

function solve(n, m, s) {
  const nums = s.split('').map(str => Number(str));
  let t = n;
  if (nums[n - 1] === 0) {
    for (let i = n - 1; i >= 0; i--) {
      if (nums[i]) {
        if (n - i - 1 <= m) {
          m -= n - i - 1;
          nums[i] = 0;
          nums[n - 1] = 1;
          t = i + 1;
        }
        break;
      }
    }
  }
  if (nums[0] === 0) {
    for (let i = 0; i < Math.min(m + 1, t - 1); i++) {
      if (nums[i]) {
        nums[i] = 0;
        nums[0] = 1;
      }
    }
  }
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += nums[i - 1] * 10 + nums[i];
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    const t1=t
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      if(t===243&&t1-t===69)console.log(`${m} ${n} ${s}`)
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';

function solve(n, m, s) {
  const nums = s.split('').map(str => Number(str));
  let t = n;
  if (nums[n - 1] === 0) {
    for (let i = n - 1; i >= 0; i--) {
      if (nums[i]) {
        if (n - i - 1 <= m) {
          m -= n - i - 1;
          nums[i] = 0;
          nums[n - 1] = 1;
          t = i + 1;
        }
        break;
      }
    }
  }
  if (nums[0] === 0) {
    for (let i = 0; i < Math.min(m + 1, t - 1); i++) {
      if (nums[i]) {
        nums[i] = 0;
        nums[0] = 1;
      }
    }
  }
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += nums[i - 1] * 10 + nums[i];
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';

function solve(n, m, s) {
  const nums = s.split('').map(str => Number(str));
  let t = n;
  if (nums[n - 1] === 0) {
    for (let i = n - 1; i >= 0; i--) {
      if (nums[i]) {
        if (n - i - 1 <= m) {
          m -= n - i - 1;
          nums[i] = 0;
          nums[n - 1] = 1;
          t = i;
        }
        break;
      }
    }
  }
  if (nums[0] === 0) {
    for (let i = 0; i <= Math.min(m, t - 1); i++) {
      if (nums[i]) {
        nums[i] = 0;
        nums[0] = 1;
      }
    }
  }
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += nums[i - 1] * 10 + nums[i];
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';

function solve(n, m, s) {
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += Number(s[i - 1] + s[i]);
  }
  let t = 0;
  if (s[n - 1] !== '1') {
    for (let i = n - 1; i >= 0; i--) {
      if (s[i] === '1') break;
      t++;
    }
    if (m >= t) {
      sum -= 10;
      m -= t;
    }
  }
  if (s[0] !== '1') {
    for (let i = 0; i < Math.min(n - t - 1, m + 1); i++) {
      if (s[i] === '1') {
        return sum - 1;
      }
    }
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';

function solve(n, m, s) {
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += Number(s[i - 1] + s[i]);
  }
  let t = 0;
  if (s[n - 1] !== '1') {
    for (let i = n - 1; i >= 0; i--) {
      if (s[i] === '1') break;
      t++;
    }
    if (m >= t) {
      sum -= 10;
      m -= t;
    }
  }
  if (s[0] !== '1') {
    for (let i = 0; i < n - t - 1; i++) {
      if (s[i] === '1') {
        if (i <= m) return sum - 1;else break;
      }
    }
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';

function solve(n, m, s) {
  let sum = 0;
  for (let i = 1; i < n; i++) {
    sum += Number(s[i - 1] + s[i]);
  }
  if (s[n - 1] !== '1') {
    let i = 0;
    while (m-- > 0) {
      if (s[n - i - 1] === '1') {
        sum -= 10;
        break;
      }
      i++;
    }
  }
  if (s[0] !== '0') {
    let i = 0;
    while (m-- > 0) {
      if (s[i] === '1') {
        sum -= 1;
        break;
      }
      i++;
    }
  }
  return sum;
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const s = await read();
      res.push(solve(n, m, s));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n, k] = ra();
  let s = readline();
  LT({n, k, s});
  // PROCESSING:
  let sum = 0;
  let lastPos = -1;
  let firstPos = -1;
  for (let i=0; i<n; i++){
    if (s[i]=='0') continue;
    if (i<n-1)
      sum += 10;
    if (i>0)
      sum += 1;
    lastPos = i;
    if (firstPos==-1)
      firstPos = i;
  }
  L({lastPos, n, k})
  let taken = true;
  if (lastPos<n-1 && lastPos>=0 && n-lastPos<=k+1){
    sum -= 10;
    k-= n-lastPos-1;
    //taken = true;
    if (lastPos==0)
      sum += 1;
  }
  if ((firstPos!=lastPos || !taken) && firstPos>0 && firstPos<=k){
    sum--;
  }
  return sum;
};

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n, k] = ra();
  let s = readline();
  LT({n, k, s});
  // PROCESSING:
  let sum = 0;
  let lastPos = -1;
  let firstPos = -1;
  for (let i=0; i<n; i++){
    if (s[i]=='0') continue;
    if (i<n-1)
      sum += 10;
    if (i>0)
      sum += 1;
    lastPos = i;
    if (firstPos==-1)
      firstPos = i;
  }
  L({lastPos, n, k})
  let taken = false;
  if (lastPos<n-1 && lastPos>=0 && n-lastPos<=k+1){
    sum -= 10;
    k-= n-lastPos-1;
    //taken = true;
    if (lastPos==0)
      sum += 1;
  }
  if ((firstPos!=lastPos || !taken) && firstPos>0 && firstPos<=k){
    sum--;
  }
  return sum;
};

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n, k] = ra();
  let s = readline();
  LT({n, k, s});
  // PROCESSING:
  let sum = 0;
  let lastPos = -1;
  let firstPos = -1;
  for (let i=0; i<n; i++){
    if (s[i]=='0') continue;
    if (i<n-1)
      sum += 10;
    if (i>0)
      sum += 1;
    lastPos = i;
    if (firstPos==-1)
      firstPos = i;
  }
  L({lastPos, n, k})
  let taken = false;
  if (lastPos<n-1 && lastPos>=0 && n-lastPos<=k+1){
    sum -= 10;
    k-= n-lastPos-1;
    taken = true;
    if (lastPos==0)
      sum += 1;
  }
  if ((firstPos!=lastPos || !taken) && firstPos>0 && firstPos<=k){
    sum--;
  }
  return sum;
};

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n, k] = ra();
  let s = readline();
  LT({n, k, s});
  // PROCESSING:
  let sum = 0;
  let lastPos = -1;
  let firstPos = -1;
  for (let i=0; i<n; i++){
    if (s[i]=='0') continue;
    if (i<n-1)
      sum += 10;
    if (i>0)
      sum += 1;
    lastPos = i;
    if (firstPos==-1)
      firstPos = i;
  }
  L({lastPos, n, k})
  if (lastPos<n-1 && lastPos>=0 && n-lastPos<=k+1){
    sum -= 10;
    k-= n-lastPos-1;
    if (lastPos==0)
      sum += 1;
  }
  if (firstPos!=lastPos && firstPos>0 && firstPos<=k){
    sum--;
  }
  return sum;
};

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n, k] = ra();
  let s = readline();
  LT({n, k, s});
  // PROCESSING:
  let sum = 0;
  let lastPos = -1;
  for (let i=0; i<n; i++){
    if (s[i]=='0') continue;
    if (i<n-1)
      sum += 10;
    if (i>0)
      sum += 1;
    lastPos = i;
  }
  L({lastPos, n, k})
  if (lastPos<n-1 && lastPos>=0 && n-lastPos<=k+1){
    sum -= 10;
    if (lastPos==0)
      sum += 1;

  }
  return sum;
};

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n, k] = ra();
  let s = readline();
  LT({n, k, s});
  // PROCESSING:
  let sum = 0;
  let lastPos = -1;
  for (let i=0; i<n; i++){
    if (s[i]=='0') continue;
    if (i<n-1)
      sum += 10;
    if (i>0)
      sum += 1;
    lastPos = i;
  }
  L({lastPos, n, k})
  if (lastPos>=0 && n-lastPos<=k+1){
    sum -= 10;
    if (lastPos==0)
      sum += 1;

  }
  return sum;
};

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);
  const results = [];
  for (let tc = 0; tc < T; tc++) {
    const [N, K] = input.next().value.split(" ").map(Number);
    let S = input.next().value.split("");
    let life = K;
    let sum = 0;
    for (let i = 1; i < N - 1; i++) {
      if (S[i] === "1") sum += 11;
    }

    let zeroPadRight = 0;
    for (let i = N - 1; i > 0; i--) {
      if (S[i] === "0") zeroPadRight += 1;
      else break;
    }
    if (zeroPadRight === N - 1) zeroPadRight = 0;

    if (S[N - 1] === "1") sum += 1;
    else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {
      sum -= 10;
      life -= zeroPadRight;
      S[N - 1] = "1";
      S[N - 1 - zeroPadRight] = "0";
    }

    let zeroPadLeft = 0;
    for (let i = 0; i < N - 1; i++) {
      if (S[i] === "0") zeroPadLeft += 1;
      else break;
    }
    if (zeroPadLeft === N - 1) zeroPadLeft = 0;

    if (S[0] === "1") sum += 10;
    else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {
      sum -= 10;
    }

    if (S[0] === "1" && S[N - 1] === "0" && life >= N - 1) {
      sum -= 9;
    }

    results.push(sum);
  }
  console.log(results.join("\n"));
}

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);
  const results = [];
  for (let tc = 0; tc < T; tc++) {
    const [N, K] = input.next().value.split(" ").map(Number);
    let S = input.next().value.split("");
    let life = K;
    let sum = 0;
    for (let i = 1; i < N - 1; i++) {
      if (S[i] === "1") sum += 11;
    }

    let zeroPadRight = 0;
    for (let i = N - 1; i > 0; i--) {
      if (S[i] === "0") zeroPadRight += 1;
      else break;
    }
    if (zeroPadRight === N - 1) zeroPadRight = 0;

    if (S[N - 1] === "1") sum += 1;
    else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {
      sum -= 10;
      life -= zeroPadRight;
      S[N - 1] = "1";
      S[N - 1 - zeroPadRight] = "0";
    }

    let zeroPadLeft = 0;
    for (let i = 0; i < N - 1; i++) {
      if (S[i] === "0") zeroPadLeft += 1;
      else break;
    }
    if (zeroPadLeft === N - 1) zeroPadLeft = 0;

    if (S[0] === "1") sum += 10;
    else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {
      sum -= 10;
    }

    if (S[0] === "1" && S[N - 1] === "1" && life >= N - 1) {
      sum -= 9;
    }

    results.push(sum);
  }
  console.log(results.join("\n"));
}

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);
  const results = [];
  for (let tc = 0; tc < T; tc++) {
    const [N, K] = input.next().value.split(" ").map(Number);
    let S = input.next().value.split("");
    let life = K;
    let sum = 0;
    for (let i = 1; i < N - 1; i++) {
      if (S[i] === "1") sum += 11;
    }

    let zeroPadRight = 0;
    for (let i = N - 1; i >= 0; i--) {
      if (S[i] === "0") zeroPadRight += 1;
      else break;
    }
    if (zeroPadRight === N) zeroPadRight = 0;

    if (S[N - 1] === "1") sum += 1;
    else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {
      sum -= 10;
      life -= zeroPadRight;
      S[N - 1] = "1";
      S[N - 1 - zeroPadRight] = "0";
    }

    let zeroPadLeft = 0;
    for (let i = 0; i < N - 1; i++) {
      if (S[i] === "0") zeroPadLeft += 1;
      else break;
    }
    if (zeroPadLeft === N - 1) zeroPadLeft = 0;

    if (S[0] === "1") sum += 10;
    else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {
      sum -= 10;
    }

    results.push(sum);
  }
  console.log(results.join("\n"));
}

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);
  const results = [];
  for (let tc = 0; tc < T; tc++) {
    const [N, K] = input.next().value.split(" ").map(Number);
    let S = input.next().value.split("");
    let life = K;
    let sum = 0;
    for (let i = 1; i < N - 1; i++) {
      if (S[i] === "1") sum += 11;
    }

    let zeroPadRight = 0;
    for (let i = N - 1; i >= 0; i--) {
      if (S[i] === "0") zeroPadRight += 1;
      else break;
    }
    if (zeroPadRight === N) zeroPadRight = 0;

    if (S[N - 1] === "1") sum += 1;
    else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {
      sum -= 10;
      life -= zeroPadRight;
      S[N - 1] = "1";
      S[N - 1 - zeroPadRight] = "0";
    }

    let zeroPadLeft = 0;
    for (let i = 0; i < N; i++) {
      if (S[i] === "0") zeroPadLeft += 1;
      else break;
    }
    if (zeroPadLeft === N) zeroPadLeft = 0;

    if (S[0] === "1") sum += 10;
    else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {
      sum -= 10;
    }

    results.push(sum);
  }
  console.log(results.join("\n"));
}

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);
  const results = [];
  for (let tc = 0; tc < T; tc++) {
    const [N, K] = input.next().value.split(" ").map(Number);
    let S = input.next().value.split("");
    let life = K;
    let sum = 0;
    for (let i = 1; i < N - 1; i++) {
      if (S[i] === "1") sum += 11;
    }

    let zeroPadRight = 0;
    for (let i = N - 1; i >= 0; i--) {
      if (S[i] === "0") zeroPadRight += 1;
      else break;
    }

    if (S[N - 1] === "1") sum += 1;
    else if (life > 0 && zeroPadRight > 0 && life >= zeroPadRight) {
      sum -= 10;
      life -= zeroPadRight;
      S[N - 1] = "1";
      S[N - 1 - zeroPadRight] = "0";
    }

    let zeroPadLeft = 0;
    for (let i = 0; i < N; i++) {
      if (S[i] === "0") zeroPadLeft += 1;
      else break;
    }
    if (S[0] === "1") sum += 10;
    else if (life > 0 && zeroPadLeft > 0 && life > zeroPadLeft) {
      sum -= 10;
    }

    results.push(sum);
  }
  console.log(results.join("\n"));
}

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);
  const results = [];
  for (let tc = 0; tc < T; tc++) {
    const [N, K] = input.next().value.split(" ").map(Number);
    let S = input.next().value.split("");
    let life = K;
    let sum = 0;
    for (let i = 1; i < N - 1; i++) {
      if (S[i] === "1") sum += 11;
    }

    let zeroPadRight = 0;
    for (let i = N - 1; i >= 0; i--) {
      if (S[i] === "0") zeroPadRight += 1;
      else break;
    }

    if (S[N - 1] === "1") sum += 1;
    else if (life !== 0 && life >= zeroPadRight) {
      sum -= 10;
      life -= zeroPadRight;
      S[N - 1] = "1";
      S[N - 1 - zeroPadRight] = "0";
    }

    let zeroPadLeft = 0;
    for (let i = 0; i < N; i++) {
      if (S[i] === "0") zeroPadLeft += 1;
      else break;
    }
    if (S[0] === "1") sum += 10;
    else if (life !== 0 && life > zeroPadLeft) {
      sum -= 10;
    }

    results.push(sum);
  }
  console.log(results.join("\n"));
}

/**
 * Format:
 * {type: 'number', namedVariable?: string }
 * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }
 * {type: 'array', namedVariable?: string }
 * {type: 'string', namedVariable?: string }
 */
const readline = require('readline');

function createCLIReader(instructions) {
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });
  const mappedVariables = {};

  let resolvePromise = null;
  const donePromise = new Promise((res, rej) => {
    resolvePromise = res;
  });

  function waitUntilDone() {
    return donePromise;
  }

  /**
   * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }
   */
  const stack = [];
  let pc = -1;

  function finished() {
    if (pc >= instructions.length) {
      return true;
    }
    return false;
  }

  function checkFinished() {
    // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);
    if (pc >= instructions.length) {
      return true;
    }
    if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {
      return true;
    }
    return false;
  }

  function getNextInstructionContext() {
    if (!stack.length) {
      return {
        index: ++pc,
      }
    }
    const lastStack = stack[stack.length - 1];
    if (lastStack.pointer === lastStack.instructionCount) {
      lastStack.pointer = 0;
      lastStack.iteration = lastStack.iteration + 1;
    }
    if (lastStack.count === lastStack.iteration) {
      stack.pop();
      pc = lastStack.basePointer + lastStack.instructionCount + 1;
      return {
        index: pc,
      }
    }

    lastStack.pointer = lastStack.pointer + 1;
    return {
      index: lastStack.basePointer + lastStack.pointer,
      context: {
        namedPath: [...lastStack.context.namedPath, lastStack.iteration]
      }
    }
  }

  function pushRepeatToStack(instruction, index, context) {
    stack.push({
      type: 'repeat',
      count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],
      iteration: 0,
      basePointer: index,
      pointer: 0,
      instructionCount: instruction.instructionCount,
      context: {
        namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],
      }
    })
    setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);
  }

  function nextInstruction() {
    if (finished()) {
      // console.warn('Calling nextInstruction after finished, something is wrong');
      return;
    }
    while (true) {
      const { index, context } = getNextInstructionContext();
      const instruction = instructions[index];

      // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);
      switch (instruction.type) {
        case 'number':
        case 'array':
        case 'string':
          return {
            ...instruction,
            namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,
          }
        case 'repeat':
          pushRepeatToStack(instruction, index, context);
          break;
        default:
          // console.warn('Unclear instruction, abort');
          return;
      }
    }
  }

  function getIn(object, path) {
    for (let i = 0; i < path.length; ++i) {
      object = object[path[i]];
    }
    return object;
  }

  function setIn(object, path, value) {
    for (let i = 0; i < path.length - 1; ++i) {
      if (object[path[i]] == null) {
        object[path[i]] = {};
      }
      object = object[path[i]];
    }
    object[path[path.length - 1]] = value;
  }

  rl.on('line', line => {
    if (finished()) {
      return;
    }
    const { type, namedPath } = nextInstruction();
    switch (type) {
      case 'number':
        if (namedPath) {
          setIn(mappedVariables, namedPath, parseInt(line));
        }
        break;
      case 'string':
        if (namedPath) {
          setIn(mappedVariables, namedPath, line.trim());
        }
        break;
      case 'array':
        if (namedPath) {
          setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));
        }
        break;
      default:
      // console.warn(`Value unread, received type ${type}.`);
    }

    if (checkFinished()) {
      resolvePromise(mappedVariables);
      rl.close();
    }
  });
  return {
    waitUntilDone,
  };
}

function solve(testCase) {
  let k = testCase.lengthAndPermit[1];

  let oneCount = 0;
  let firstOne = -1;
  let lastOne = -1;
  for (let i = 0; i < testCase.theInput.length; ++i) {
    if (testCase.theInput[i] === '1') {
      if (firstOne === -1) {
        firstOne = i;
      }
      lastOne = i;
      ++oneCount;
    }
  }

  if (oneCount === 0) {
    return 0;
  }

  if (oneCount === testCase.theInput.length) {
    return 11 * (oneCount - 1);
  }

  let preliminarySum = 11 * oneCount;
  const distanceToLast = testCase.theInput.length - 1 - lastOne;
  const distanceToFirst = firstOne;

  if (k - distanceToLast >= 0) {
    k -= distanceToLast;
    preliminarySum -= 10;
  }
  if (k - distanceToFirst >= 0 && oneCount > 1) {
    preliminarySum -= 1;
  }

  return preliminarySum;
}

(async function main() {
  const reader = createCLIReader([
    { type: 'number', namedVariable: 'numberOfTestCase' },
    { type: 'repeat', instructionCount: 2, count: 'numberOfTestCase', namedVariable: 'testCase' },
    { type: 'array', namedVariable: 'lengthAndPermit' },
    { type: 'string', namedVariable: 'theInput' }
  ]);
  const schema = await reader.waitUntilDone();

  for (let i = 0; i < schema.numberOfTestCase; ++i) {
    console.log(solve(schema.testCase[i]));
  }
})();

/**
 * Format:
 * {type: 'number', namedVariable?: string }
 * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }
 * {type: 'array', namedVariable?: string }
 * {type: 'string', namedVariable?: string }
 */
const readline = require('readline');

function createCLIReader(instructions) {
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });
  const mappedVariables = {};

  let resolvePromise = null;
  const donePromise = new Promise((res, rej) => {
    resolvePromise = res;
  });

  function waitUntilDone() {
    return donePromise;
  }

  /**
   * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }
   */
  const stack = [];
  let pc = -1;

  function finished() {
    if (pc >= instructions.length) {
      return true;
    }
    return false;
  }

  function checkFinished() {
    // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);
    if (pc >= instructions.length) {
      return true;
    }
    if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {
      return true;
    }
    return false;
  }

  function getNextInstructionContext() {
    if (!stack.length) {
      return {
        index: ++pc,
      }
    }
    const lastStack = stack[stack.length - 1];
    if (lastStack.pointer === lastStack.instructionCount) {
      lastStack.pointer = 0;
      lastStack.iteration = lastStack.iteration + 1;
    }
    if (lastStack.count === lastStack.iteration) {
      stack.pop();
      pc = lastStack.basePointer + lastStack.instructionCount + 1;
      return {
        index: pc,
      }
    }

    lastStack.pointer = lastStack.pointer + 1;
    return {
      index: lastStack.basePointer + lastStack.pointer,
      context: {
        namedPath: [...lastStack.context.namedPath, lastStack.iteration]
      }
    }
  }

  function pushRepeatToStack(instruction, index, context) {
    stack.push({
      type: 'repeat',
      count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],
      iteration: 0,
      basePointer: index,
      pointer: 0,
      instructionCount: instruction.instructionCount,
      context: {
        namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],
      }
    })
    setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);
  }

  function nextInstruction() {
    if (finished()) {
      // console.warn('Calling nextInstruction after finished, something is wrong');
      return;
    }
    while (true) {
      const { index, context } = getNextInstructionContext();
      const instruction = instructions[index];

      // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);
      switch (instruction.type) {
        case 'number':
        case 'array':
        case 'string':
          return {
            ...instruction,
            namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,
          }
        case 'repeat':
          pushRepeatToStack(instruction, index, context);
          break;
        default:
          // console.warn('Unclear instruction, abort');
          return;
      }
    }
  }

  function getIn(object, path) {
    for (let i = 0; i < path.length; ++i) {
      object = object[path[i]];
    }
    return object;
  }

  function setIn(object, path, value) {
    for (let i = 0; i < path.length - 1; ++i) {
      if (object[path[i]] == null) {
        object[path[i]] = {};
      }
      object = object[path[i]];
    }
    object[path[path.length - 1]] = value;
  }

  rl.on('line', line => {
    if (finished()) {
      return;
    }
    const { type, namedPath } = nextInstruction();
    switch (type) {
      case 'number':
        if (namedPath) {
          setIn(mappedVariables, namedPath, parseInt(line));
        }
        break;
      case 'string':
        if (namedPath) {
          setIn(mappedVariables, namedPath, line.trim());
        }
        break;
      case 'array':
        if (namedPath) {
          setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));
        }
        break;
      default:
      // console.warn(`Value unread, received type ${type}.`);
    }

    if (checkFinished()) {
      resolvePromise(mappedVariables);
      rl.close();
    }
  });
  return {
    waitUntilDone,
  };
}

function solve(testCase) {
  let k = testCase.lengthAndPermit[1];

  let oneCount = 0;
  let firstOne = -1;
  let lastOne = -1;
  for (let i = 0; i < testCase.theInput.length; ++i) {
    if (testCase.theInput[i] === '1') {
      if (firstOne === -1) {
        firstOne = i;
      }
      lastOne = i;
      ++oneCount;
    }
  }

  if (oneCount === 0) {
    return 0;
  }

  if (oneCount === testCase.theInput.length) {
    return 11 * (oneCount - 1);
  }

  let preliminarySum = 11 * oneCount;
  const distanceToLast = testCase.theInput.length - 1 - lastOne;
  const distanceToFirst = firstOne;

  if (k - distanceToLast >= 0) {
    k -= distanceToLast;
    preliminarySum -= 10;
  }
  if (k - distanceToFirst >= 0) {
    preliminarySum -= 1;
  }

  return preliminarySum;
}

(async function main() {
  const reader = createCLIReader([
    { type: 'number', namedVariable: 'numberOfTestCase' },
    { type: 'repeat', instructionCount: 2, count: 'numberOfTestCase', namedVariable: 'testCase' },
    { type: 'array', namedVariable: 'lengthAndPermit' },
    { type: 'string', namedVariable: 'theInput' }
  ]);
  const schema = await reader.waitUntilDone();

  for (let i = 0; i < schema.numberOfTestCase; ++i) {
    console.log(solve(schema.testCase[i]));
  }
})();

class Scaner {
    data = [];
    constructor() {
        process.stdin.setEncoding('utf-8');
        process.stdin.on('data', _data => {
            let lasttext = this.data.pop();
            if (lasttext == undefined)
                lasttext = ""
            _data = lasttext + _data;
            const l = _data.split('\n');
            this.data = this.data.concat(l.slice(0, -1).map(string => string.trim()), l[l.length - 1]);
        });
    }
    read = async () => {
        process.stdin.resume();
        while (this.data.length < 2) {
            await delay(0);
        }
        process.stdin.pause();
        let res = this.data.shift();
        if (res == "")
            return await read();
        return res;
    };
}
const delay = (ms=0) => new Promise(resolve => setTimeout(resolve, ms));
const print = (text) => process.stdout.write("" + text);
const scaner = new Scaner()
const read = scaner.read;
//----------------------------------------------------------------
//-----------------------the-code---------------------------------
//----------------------------------------------------------------

(async () => {
    let t = parseInt(await read());
    while (t--) {
        let [n,k]=(await read()).split(' ').map(Number);
        let a=await read();
        let ans=0;
        let i,j;
        for (i = a.length-1; i >= 0; i--){
            const e = a[i];
            if(e=='1'){
                const cost=a.length-i-1;
                if(cost<=k){
                    k-=cost;
                    ans+=1;
                }else{
                    ans+=11;
                }
                break;
            }
        }
        for (j = 0; j < i; j++){
            const e = a[j];
            if(e=='1'){
                const cost=j;
                if(cost<=k){
                    k-=cost;
                    ans+=10;
                }else{
                    ans+=11;
                }
                break;

            }
        }
        for (j++; j < i; j++){
            if(a[j]=='1'){
                ans+=11;
            }
        }
        console.log(ans);
    }
})().then(() => { }
)


Polycarp has guessed three positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$.You have to guess three numbers $$$a$$$, $$$b$$$ and $$$c$$$ using given numbers. Print three guessed integers in any order.Pay attention that some given numbers $$$a$$$, $$$b$$$ and $$$c$$$ can be equal (it is also possible that $$$a=b=c$$$).

The only line of the input contains four positive integers $$$x_1, x_2, x_3, x_4$$$ ($$$2 \le x_i \le 10^9$$$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $$$x_1, x_2, x_3, x_4$$$.

Print such positive integers $$$a$$$, $$$b$$$ and $$$c$$$ that four numbers written on a board are values $$$a+b$$$, $$$a+c$$$, $$$b+c$$$ and $$$a+b+c$$$ written in some order. Print $$$a$$$, $$$b$$$ and $$$c$$$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists.

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var numbers = read.arrNumber(' ');

    numbers.sort((a, b) => a - b);

    var a = numbers[3] - numbers[2];
    var b = numbers[1] - a;
    var c = numbers[0] - a;
    print(a + ' ' + b + ' ' + c);
}());

var n = readline().split(' ').map(Number);
n.sort((a,b) => a-b);

var a = n[3]-n[0];
var b = n[3]-n[1];
var c = n[3]-n[2];

print(a,b,c);

var numbers = readline().split(" ").map(function(x) { return parseInt(x); });
var x1 = numbers[0];
var x2 = numbers[1];
var x3 = numbers[2];
var x4 = numbers[3];
 var maxX = 0;
 var massiveXes = [];
 var a;
 var b;
 var c;
 massiveXes.push(x2, x1, x3, x4);

 for (i = 0; i< massiveXes.length; i++){
	if (maxX < massiveXes[i]){
		maxX = massiveXes[i];
	}

 }

 for (k=0; k<massiveXes.length; k++){
	 if (maxX == massiveXes[k]){
		 massiveXes.splice (k,1);

	 }

 }
 a = maxX - massiveXes[0];
 b = maxX - massiveXes[1];
 c = maxX - massiveXes[2];

 print (a, b, c);

var ns = readline().split(' ').map(z => parseInt(z))
var total = ns.reduce((p, c) => p > c ? p : c)
ns.splice(ns.indexOf(total), 1)
var get = (x, y, z) => {
    var c = Math.abs((((x - y) + (x - z)) - x) / 2)
    return [c, x - z + c, x - y + c]
}
var o = [
    [0, 1, 2],
    [0, 2, 1],
    [1, 0, 2],
    [1, 2, 0],
    [2, 0, 1],
    [2, 1, 0]
].map(z => z.map(y => ns[y]))
    .map(z => get.apply([], z))
    .filter(z => z.reduce((p, c) => p + c) == total)[0]
    .sort((a, b) => a - b)
    .join(" ")
print(o)

var n = readline().split(' ').map(Number);
// var n = prompt().split(' ').map(Number);
n.sort((a,b) => a-b);
var a = n[3]-n[0];
var b = n[3]-n[1];
var c = n[3]-n[2];
// console.log(a, b, c);
print(a, b, c);

var n = readline().split(' ').map(Number);
n.sort((a,b) => a-b);
var a = n[3]-n[0];
var b = n[3]-n[1];
var c = n[3]-n[2];
print(a, b, c);

var s = readline().split(" ").map(function(e){return parseInt(e);});
var x = Math.max(...s);var b = s.indexOf(x);

var show = "";for(var i=0;i<s.length;i++){
if(i!==b){show += (x-s[i]) + " ";}
}

print(show.slice(0,show.length - 1));

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var input = rdArN().sortGt();
    wr(
        input[0] - input[1],
        input[0] - input[2],
        input[0] - input[3]
    );
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

//var input = readline()

var ar = readline().split(' ').map(x => parseInt(x))
ar.sort((a, b) => a - b)
var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]]
print(k.join(' '))

//

'use strict';

const fs = require('fs');

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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function readLine() {
    return inputString[currentLine++].split(' ');
}

function readInt(s) {
    return parseInt(s, 10);
}

function readIntArray(a) {
    return a.map(e => parseInt(e, 10));
}

function solve(n) {
    n.sort((a, b) => a - b);
    return [n[3] - n[0], n[3] - n[2], n[3] - n[1]];
}

function main() {

    const n = readIntArray(readLine());

    let result = solve(n);
    console.log(result.join(' '));
}

const readline = require('readline')

async function algo() {
  let [x, y, z, k] = await ints()
  let i = 0
  if (k < x) [k, x] = [x, k]
  if (k < y) [k, y] = [y, k]
  if (k < z) [k, z] = [z, k]
  const a = k - x
  console.log([a, y-a, z-a].join(' '))
}

// read the input
const _lines = []
let _lineIndex = 0
let _ended = false
const _rl = readline.createInterface(process.stdin)
_rl.on('line', line => _lines.push(line))
_rl.on('end', () => (ended = true))
const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
const line = async () => {
  while (!_ended && _lines.length <= _lineIndex) await wait(10)
  const result = _lines[_lineIndex].trim()
  _lines[_lineIndex] = null
  _lineIndex++
  return result
}
const words = async () => (await line()).split(' ')
const chars = async () => (await line()).split('')
const int = async () => parseInt(await line())
const ints = async () => (await words()).map(x => parseInt(x))
const big = async () => BigInt(await line())
const bigs = async () => (await words()).map(x => BigInt(x))

algo()

const readline = require('readline');

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

rl.on('line', (line) => {
  let numbers = [];
  let addedNumbers = line.split(' ').map(Number);
  let abc = Math.max(...addedNumbers);
  addedNumbers.splice(addedNumbers.indexOf(abc), 1);
  addedNumbers.forEach((number) => {
    numbers.push(abc - number);
  });

  console.log(...numbers);
});

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

intInput.on('line', (line) => {
	nums = line.split(" ");
});

intInput.on('close', () => {
	let max = Number(nums[0]);
	let maxI = 0;
	for (let i = 1; i < nums.length; i++) {
		if ( nums[i] > max) {
			max = Number(nums[i]);
			maxI = i
		}
	}
	nums.splice(maxI, 1);
	let result = "";
	for (let j = 0; j < nums.length; j++) {
		let a = max - Number(nums[j]);
		j == nums.length -1 ? result += `${a}` : result += `${a}` + " ";
	}
	console.log(result);
})

function main() {
    // write code here:
    var arr=(stdin[0].split(' ')).map(a => Number(a)).sort((a,b) => a-b);
    var a=arr[3]-arr[2],b=arr[3]-arr[1],c=arr[3]-arr[0];
    console.log(a,b,c);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

const readline = require("readline");

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

rl.question('', function (results) {
    const res = results.split(' ').map(num => parseInt(num));
    calNums(res);
    rl.close();
});

rl.on("close", function () {
    process.exit(0);
});

function calNums(res) {
    let a = 0, b = 0, c = 0;
    res.sort(function (a, b) { return a - b });
    b = (res[0] - res[1] + res[2]) / 2;
    a = res[0] - b ;
    c = res[2] - b  ;

    console.log(`${a} ${b} ${c}`);
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
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";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//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 one = nextIntArray();
  one.sort(function(a, b){
  	return a - b;
  });
  var L = one[3] - one[2];
  var C = one[3] - one[1];
  var R = one[3] - one[0];
  myout(L + " " + C + " " + R);
}

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

rl.on('line', (d) => {
  const ans = [];
  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  for (let i = 0; i < arr.length - 1; i++) {
    ans.push(arr[arr.length - 1] - arr[i]);
  }

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

let input = [];

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

RL.on('line', (line) => {
    input.push(line);
});

RL.on('close', () => {
    let {0:x1, 1:x2, 2:x3, 3:x4} = {...input[0].split(' ')};
    x1 = parseInt(x1); x2 = parseInt(x2);
    x3 = parseInt(x3); x4 = parseInt(x4);
    let max = (x1 > x2 && x1 > x3 && x1 > x4) ? x1 :
        (x2 > x1 && x2 > x3 && x2 > x4) ? x2 :
        (x3 > x1 && x3 > x2 && x3 > x4) ? x3 : x4;

    input[0].split(' ').forEach( i => {
        if(parseInt(i) != parseInt(max))
            console.log(max - i);
    });
});

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [x1, x2, x3, x4] = input[0].split(' ').map(x => parseInt(x));

  let max = Math.max(x1, x2, x3, x4);
  const nums = [];

  input[0].split(' ').map(x => parseInt(x)).forEach( x => {
    if (x !== max) {
      nums.push(max - x);
    }
  });

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');
    main();
});

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

// main function .... code start ... ///
function main() {

    //var input = readline()
    var ar = readline().split(' ').map(x => parseInt(x))
    ar.sort((a, b) => a - b)
    var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]]
    console.log(k.join(' '))
}

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

// ************************ Code Start ***************************

function main() {
  //var input = readline();
  var ar = readline().split(" ").map(x => parseInt(x));
  ar.sort((a, b) => a - b);
  var k = [ar[3] - ar[2], ar[3] - ar[1], ar[3] - ar[0]];
  print(k.join(" "));
}

//******************************************************************************** //
'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.split('\n'); main(); }); //
function readline() { return inputString[currentLine++]; }                         //
//******************************************************************************** //

function main() {

    //var input = readline()
    var ar = readline().split(' ').map(x => parseInt(x))
    ar.sort((a, b) => a - b)
    var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]]
    console.log(k.join(' '))

}

'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.split('\n');
    main();
});
function readline() {
    return inputString[currentLine++];
}
// ******************************************************
// ******************** Code Start **********************

function main() {

    //var input = readline();
    var ar = readline().split(' ').map(x => parseInt(x)) ;
    ar.sort((a, b) => a - b);
    var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]];
    console.log(k.join(' '));

}

//******************************************************************************** //
'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.split('\n'); main(); }); //
function readline() { return inputString[currentLine++]; }                         //
                                                                                //
//******************************************************************************** //

function main() {

    //var input = readline()
    var ar = readline().split(' ').map(x => parseInt(x))
    ar.sort((a, b) => a - b)
    var k = [ar[3]-ar[2], ar[3]-ar[1], ar[3]-ar[0]]
    console.log(k.join(' '))

}

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
       arr = arr.split('\n');
       arr.pop();
       let num = arr[0].split(' ');
       //num.pop();
       let a = parseInt(num[0]);
       let b = parseInt(num[1]);
       let c = parseInt(num[2]);
       let d = parseInt(num[3]);
       let max = 0;
       if(a>b && a>c && a>d) max = a;
       else if(b>a && b>c && b>d) max =b;
       else if(c>a && c>b && c>d) max =c;
       else max =d;

       let str,str1,str2,str3;
       (max !==a)?str = max-a:str='';
       (max !==b)?str1 =max-b:str1='';
       (max !==c)?str2 =max-c:str2='';
       (max !==d)?str3 =max-d:str3='';
       console.log(str+" "+str1+" "+str2+" "+str3);
    });

// Sample code to perform I/O:

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

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split(' ').map(num => Number(num));
    let max = Math.max(...inputs);
    let newNum = [];
    for (const iterator of inputs) {
        if (iterator !== max) {
            newNum.push(max - iterator);
        }
    }
    return newNum.join(' ').toString();
}

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let arr = readLine().split(' ').map(v => parseInt(v)).sort((a, b) => {
        return a - b;
    });
    let x1 = arr[0];
    let x2 = arr[1];
    let x3 = arr[2];
    let x4 = arr[3];
    console.log(x3 - (x4 - x1), x2 - (x4 - x1), x4 - x1)
}

const readline = require('readline')

async function algo() {
  const [x, y, z, k] = await ints()
  let i = 0
  if (k < x) [k, x] = [x, k]
  if (k < y) [k, y] = [y, k]
  if (k < z) [k, z] = [z, k]
  const a = k - x
  console.log([a, y-a, z-a].join(' '))
}

// read the input
const _lines = []
let _lineIndex = 0
let _ended = false
const _rl = readline.createInterface(process.stdin)
_rl.on('line', line => _lines.push(line))
_rl.on('end', () => (ended = true))
const wait = ms => new Promise(resolve => setTimeout(resolve, ms))
const line = async () => {
  while (!_ended && _lines.length <= _lineIndex) await wait(10)
  const result = _lines[_lineIndex].trim()
  _lines[_lineIndex] = null
  _lineIndex++
  return result
}
const words = async () => (await line()).split(' ')
const chars = async () => (await line()).split('')
const int = async () => parseInt(await line())
const ints = async () => (await words()).map(x => parseInt(x))
const big = async () => BigInt(await line())
const bigs = async () => (await words()).map(x => BigInt(x))

algo()

const readline = require('readline');

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

rl.on('line', (line) => {
  let numbers = [];
  let addedNumbers = line.split(' ').map(Number);
  let abc = Math.max(...addedNumbers);
  addedNumbers.splice(addedNumbers.indexOf(abc), 1);
  addedNumbers.forEach((number) => {
    numbers.push(abc - number);
  });

  return {...numbers};
});

const readline = require('readline');

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

rl.on('line', (line) => {
  let numbers = [];
  let addedNumbers = line.split(' ').map(Number);
  let abc = Math.max(...addedNumbers);
  addedNumbers.splice(addedNumbers.indexOf(abc), 1);
  addedNumbers.forEach((number) => {
    numbers.push(abc - number);
  });

  return numbers.join(' ');
});

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

intInput.on('line', (line) => {
	nums = line.split(" ");
});

intInput.on('close', () => {
	let max = nums[0];
	let maxI = 0;
	for (let i = 1; i < nums.length; i++) {
		if ( nums[i] > max) {
			max = Number(nums[i]);
			maxI = i
		}
	}
	nums.splice(maxI, 1);
	let result = "";
	for (let j = 0; j < nums.length; j++) {
		let a = max - Number(nums[j]);
		j == nums.length -1 ? result += `${a}` : result += `${a}` + " ";
	}
	console.log(result);
})

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
       arr = arr.split('\n');
       arr.pop();
       console.log("for arr");
       console.log(arr);
       let num = arr[0].split(' ');
       num.pop();
       console.log("for num");
       console.log(num);
       let a = parseInt(num[0]);
       console.log("for a:"+a);
       let b = parseInt(num[1]);
       console.log("for b:"+b);
       let c = parseInt(num[2]);
       console.log("for c:"+c);
       let d = parseInt(num[3]);
       console.log("for d:"+d);
    });

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
       arr = arr.split('\n');
       arr.pop();
       console.log("for arr");
       console.log(arr);
       let num = arr[0].split(' ');
       //num.pop();
       console.log("for num");
       console.log(num);
       let a = parseInt(num[0]);
       console.log("for a:"+a);
       let b = parseInt(num[1]);
       console.log("for b:"+b);
       let c = parseInt(num[2]);
       console.log("for c:"+c);
       let d = parseInt(num[3]);
       console.log("for d:"+d);
    });

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
       arr = arr.split('\n');
       arr.pop();
       console.log("for arr");
       console.log(arr);
       let num = arr[0].split(' ');
       num.pop();
       console.log("for num");
       console.log(num);
       let a = parseInt(num[0]);
       console.log("for a:"+a);
       let b = parseInt(num[1]);
       console.log("for b:"+b);
       let c = parseInt(num[2]);
       console.log("for c:"+c);
    });

var arr = '';
process.stdin.on('data',function(chunk){
   arr += chunk;
});
process.stdin.on('end',function(){
   arr = arr.split('\n');
   arr.pop();
   console.log("for arr");
   console.log(arr);
});

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
       arr = arr.split('\n');
       arr.pop();
       console.log("for arr");
       console.log(arr);
       let num = arr[0].split(' ');
       //num.pop();
       console.log("for num");
       console.log(num);
       let a = parseInt(num[0]);
       console.log("for a:"+a);
       let b = parseInt(num[1]);
       console.log("for b:"+b);
       let c = parseInt(num[2]);
       console.log("for c:"+c);
       let d = parseInt(num[3]);
       console.log("for d:"+d);
       let max = 0;
       if(a>b && a>c && a>d) max = a;
       else if(b>a && b>c && b>d) max =b;
       else if(c>a && c>b && c>d) max =c;
       else max =d;
       console.log((max-a)+" "+(max-b)+" "+(max-c)+" "+(max-d));
    });

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
       arr = arr.split('\n');
       arr.pop();
       console.log("for arr");
       console.log(arr);
       let num = arr[0].split(' ');
       //num.pop();
       console.log("for num");
       console.log(num);
       let a = parseInt(num[0]);
       console.log("for a:"+a);
       let b = parseInt(num[1]);
       console.log("for b:"+b);
       let c = parseInt(num[2]);
       console.log("for c:"+c);
       let d = parseInt(num[3]);
       console.log("for d:"+d);
       let max = 0;
       if(a>b && a>c && a>d) max = a;
       else if(b>a && b>c && b>d) max =b;
       else if(c>a && c>b && c>d) max =c;
       else max =d;

       let str = '';
       if(max !==a) str = str + (max-a);
       if(max !==b) str = str + (max-b);
       if(max !==c) str = str + (max-c);
       if(max !==d) str = str + (max-d);
       console.log("for str:"+str);
       str = str.split('');
       console.log(str.join(' '));
       //console.log((max-a)+" "+(max-b)+" "+(max-c)+" "+(max-d));
    });

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
       arr = arr.split('\n');
       arr.pop();
       let num = arr[0].split(' ');
       //num.pop();
       let a = parseInt(num[0]);
       let b = parseInt(num[1]);
       let c = parseInt(num[2]);
       let d = parseInt(num[3]);
       let max = 0;
       if(a>b && a>c && a>d) max = a;
       else if(b>a && b>c && b>d) max =b;
       else if(c>a && c>b && c>d) max =c;
       else max =d;

       let str = '';
       if(max !==a) str = str + (max-a);
       if(max !==b) str = str + (max-b);
       if(max !==c) str = str + (max-c);
       if(max !==d) str = str + (max-d);
       str = str.split('');
       console.log(str.join(' '));
    });

    var arr = '';
    process.stdin.on('data',function(chunk){
       arr += chunk;
    });
    process.stdin.on('end',function(){
       arr = arr.split('\n');
       arr.pop();
       console.log("for arr");
       console.log(arr);
       let num = arr[0].split(' ');
       num = num.pop();
       console.log("for num");
       console.log(num);
       let a = parseInt(num[0]);
       console.log("for a:"+a);
       let b = parseInt(num[1]);
       console.log("for b:"+b);
       let c = parseInt(num[2]);
       console.log("for c:"+c);
    });

var arr = '';
process.stdin.on('data',function(chunk){
   arr += chunk;
});
process.stdin.on('end',function(){
   arr = arr.split('\n');
   arr.pop();
   console.log("for arr");
   console.log(arr);
   let a = parseInt(arr[0]);
   console.log("for a:"+a);
   let b = parseInt(arr[1]);
   console.log("for b:"+b);
   let c = parseInt(arr[2]);
   console.log("for c:"+c);
});

var arr = '';
process.stdin.on('data',function(chunk){
   arr += chunk;
});
process.stdin.on('end',function(){
   arr = arr.split('\n');
   console.log("for arr");
   console.log(arr);
});

var arr = '';
process.stdin.on('data',function(chunk){
   arr += chunk;
});
console.log("for arr");
console.log(arr);

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let arr = readLine().split(' ').map(v => parseInt(v)).sort();
    let x1 = arr[0];
    let x2 = arr[1];
    let x3 = arr[2];
    let x4 = arr[3];
    console.log(x3 - (x4 - x1), x2 - (x4 - x1), x4 - x1)
}

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let arr = readLine().split(' ').map(v => parseInt(v)).sort((a, b) => {
        return a - b;
    });
    console.log(arr);
    let x1 = arr[0];
    let x2 = arr[1];
    let x3 = arr[2];
    let x4 = arr[3];
    console.log(x3 - (x4 - x1), x2 - (x4 - x1), x4 - x1)
}


You are given a binary array $$$a$$$ (all elements of the array are $$$0$$$ or $$$1$$$) of length $$$n$$$. You wish to sort this array, but unfortunately, your algorithms teacher forgot to teach you sorting algorithms. You perform the following operations until $$$a$$$ is sorted:  Choose two random indices $$$i$$$ and $$$j$$$ such that $$$i < j$$$. Indices are chosen equally probable among all pairs of indices $$$(i, j)$$$ such that $$$1 \le i < j \le n$$$.  If $$$a_i > a_j$$$, then swap elements $$$a_i$$$ and $$$a_j$$$. What is the expected number of such operations you will perform before the array becomes sorted?It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{998\,244\,353}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod 998\,244\,353$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x < 998\,244\,353$$$ and $$$x \cdot q \equiv p \pmod{998\,244\,353}$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^5$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of elements in the binary array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i \in \{0, 1\}$$$) — elements of the array. It's guaranteed that sum of $$$n$$$ over all test cases does not exceed $$$200\,000$$$.

For each test case print one integer — the value $$$p \cdot q^{-1} \bmod 998\,244\,353$$$.

NoteConsider the first test case. If the pair of indices $$$(2, 3)$$$ will be chosen, these elements will be swapped and array will become sorted. Otherwise, if one of pairs $$$(1, 2)$$$ or $$$(1, 3)$$$ will be selected, nothing will happen. So, the probability that the array will become sorted after one operation is $$$\frac{1}{3}$$$, the probability that the array will become sorted after two operations is $$$\frac{2}{3} \cdot \frac{1}{3}$$$, the probability that the array will become sorted after three operations is $$$\frac{2}{3} \cdot \frac{2}{3} \cdot \frac{1}{3}$$$ and so on. The expected number of operations is $$$\sum \limits_{i=1}^{\infty} \left(\frac{2}{3} \right)^{i - 1} \cdot \frac{1}{3} \cdot i = 3$$$.In the second test case the array is already sorted so the expected number of operations is zero.In the third test case the expected number of operations equals to $$$\frac{75}{4}$$$ so the answer is $$$75 \cdot 4^{-1} \equiv 249\,561\,107 \pmod {998\,244\,353}$$$.

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    let zero = 0
    for (let i = 0; i < n; i++) {
        if (!arr[i]) zero++
    }
    let one = 0
    for (let i = 0; i < zero; i++) {
        if (arr[i]) one++
    }
// console.log(one)
    let r = 0
    const c2 = mul(n, n - 1)
    for (let i = 1; i <= one; i++) {
        // i * i * 2 / (n * (n - 1))
        const i2 = mul(i, i * 2)
        const temp = mul(c2, pow(i2, MOD - 2))
        r = add(r, temp)
    }
    return r
}
const MOD = 998244353
const MOD_CUT = ((1 << 20) * (1 << 20)) % MOD
function add(a, b) {
    return (a + b) % MOD
}
function minus(a, b) {
    return add(add(a, -b), MOD)
}
function mul(a, b) {
    let r = (a >> 20) * (b >> 20) * MOD_CUT
        + (a & 0xfff00000) * (b & 0xfffff)
        + (a & 0xfffff) * b
    return r % MOD
}
function pow(a, b) {
    let r = 1
    let base = a
    while (b) {
        if (b & 1) {
            r = mul(r, base)
        }
        b >>= 1
        base = mul(base, base)
    }
    return r
}


In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).

Print a single number — the sought number of days.

NoteIn the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.