One day, Pak Chanek who is already bored of being alone at home decided to go traveling. While looking for an appropriate place, he found that Londonesia has an interesting structure.According to the information gathered by Pak Chanek, there are $$$N$$$ cities numbered from $$$1$$$ to $$$N$$$. The cities are connected to each other with $$$N-1$$$ two-directional roads, with the $$$i$$$-th road connecting cities $$$U_i$$$ and $$$V_i$$$, and taking a time of $$$W_i$$$ hours to be traversed. In other words, Londonesia's structure forms a tree.Pak Chanek wants to go on a journey in Londonesia starting and ending in any city (not necessarily the same city) such that each city is visited at least once with the least time possible. In order for the journey to end quicker, Pak Chanek also carries an instant teleportation device for moving from one city to any city that can only be used at most once. Help Pak Chanek for finding the minimum time needed.Notes:   Pak Chanek only needs to visit each city at least once. Pak Chanek does not have to traverse each road.  In the journey, a city or a road can be visited more than once.

The first line contains a single integer $$$N$$$ ($$$1 \le N \le 10^5$$$) — the number of cities in Londonesia. The $$$i$$$-th of the next $$$N-1$$$ lines contains three integers $$$U_i$$$, $$$V_i$$$, and $$$W_i$$$ ($$$1 \le U_i, V_i \le N$$$, $$$1 \le W_i \le 10^9$$$) — a two-directional road that connects cities $$$U_i$$$ and $$$V_i$$$ that takes $$$W_i$$$ hours to be traversed. The roads in Londonesia form a tree.

Output one integer, which represents the minimum time in hours that is needed to visit each city at least once.

NoteIn the first example, the journey that has the minimum time is $$$2 → 1 \xrightarrow{\text{teleport}} 4 → 3$$$.In the second example, the journey that has the minimum time is $$$3 → 1 → 4 → 1 → 2 \xrightarrow{\text{teleport}} 5$$$.

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => [0, 0, 0, 0]),
        max = Array.from({
    length: n
  }, () => []),
        dp1 = new Array(n).fill(0);
  const sums = new Array(n).fill(0);
  const dfs = u => {
    let queue = [[u, -1]];
    const p = [];
    const d = new Array(n).fill(0);
    for (let [u, from] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        p[v] = [u, i];
        d[u]++;
        queue.push([v, i]);
      }
    }
    {
      let queue = [];
      for (let i = 0; i < n; i++) {
        if (!d[i]) {
          queue.push(i);
        }
      }
      for (let v of queue) {
        if (!p[v]) continue;
        const [u, i] = p[v];
        let ans = dp[v][0] + w[i];
        if (dp[u][0] <= ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = dp[u][1];
          dp[u][1] = dp[u][0];
          dp[u][0] = ans;
          max[u][1] = max[u][0];
          max[u][0] = v;
        } else if (dp[u][1] <= ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = dp[u][1];
          dp[u][1] = ans;
          max[u][1] = v;
        } else if (dp[u][2] <= ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = ans;
        } else if (dp[u][3] < ans) {
          dp[u][3] = ans;
        }
        dp1[v] = Math.max(dp1[v], dp[v][0] + dp[v][1]);
        dp1[u] = Math.max(dp1[u], dp1[v]);
        sums[u] += sums[v] + w[i];
        d[u]--;
        if (!d[u]) queue.push(u);
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = u => {
    const queue = [[u, -1, 0, 0]];
    for (let [u, from, d, maxd] of queue) {
      let x = -1;
      if (d) {
        for (let i = 0; i < 4; i++) {
          if (d >= dp[u][i]) {
            [d, dp[u][i]] = [dp[u][i], d];
            if (i < 2) [x, max[u][i]] = [max[u][i], x];
          }
        }
      }
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        let nd = dp[u][0],
            a = maxd;
        if (max[u][0] === v) {
          nd = dp[u][1];
          a = Math.max(a, dp[u][1] + dp[u][2]);
        } else if (max[u][1] === v) {
          a = Math.max(maxd, dp[u][0] + dp[u][2]);
        } else {
          a = Math.max(maxd, dp[u][0] + dp[u][1]);
        }
        queue.push([v, i, nd + w[i], a]);
        {
          let b = (sum - sums[v] - w[i] - a) * 2;
          let c = dp1[v];
          let e = (sums[v] - c) * 2;
          res = Math.min(res, a + b + c + e);
        }
      }
      {
        res = Math.min(res, 2 * sum - dp[u].reduce((a, b) => a + b, 0));
      }
    }
  };
  dfs1(0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => [0, 0, 0, 0]),
        max = Array.from({
    length: n
  }, () => []),
        dp1 = new Array(n).fill(0);
  const sums = new Array(n).fill(0);
  const dfs = u => {
    let queue = [[u, -1]];
    const p = [];
    const d = new Array(n).fill(0);
    for (let [u, from] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        p[v] = [u, i];
        d[u]++;
        queue.push([v, i]);
      }
    }
    {
      let queue = [];
      for (let i = 0; i < n; i++) {
        if (!d[i]) {
          queue.push(i);
        }
      }
      for (let v of queue) {
        if (!p[v]) continue;
        const [u, i] = p[v];
        let ans = dp[v][0] + w[i];
        if (dp[u][0] <= ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = dp[u][1];
          dp[u][1] = dp[u][0];
          dp[u][0] = ans;
          max[u][1] = max[u][0];
          max[u][0] = v;
        } else if (dp[u][1] <= ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = dp[u][1];
          dp[u][1] = ans;
          max[u][1] = v;
        } else if (dp[u][2] <= ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = ans;
        } else if (dp[u][3] < ans) {
          dp[u][3] = ans;
        }
        dp1[v] = Math.max(dp1[v], dp[v][0] + dp[v][1]);
        dp1[u] = Math.max(dp1[u], dp1[v]);
        sums[u] += sums[v] + w[i];
        d[u]--;
        if (!d[u]) queue.push(u);
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = u => {
    const queue = [[u, -1, 0, 0]];
    for (let [u, from, d, maxd] of queue) {
      let x = -1;
      for (let i = 0; i < 4; i++) {
        if (d >= dp[u][i]) {
          [d, dp[u][i]] = [dp[u][i], d];
          if (i < 2) [x, max[u][i]] = [max[u][i], x];
        }
      }
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        let nd = dp[u][0],
            a = maxd;
        if (max[u][0] === v) {
          nd = dp[u][1];
          a = Math.max(a, dp[u][1] + dp[u][2]);
        } else {
          a = Math.max(maxd, dp[u][0] + dp[u][1]);
        }
        queue.push([v, i, nd + w[i], a]);
        {
          let b = (sum - sums[v] - w[i] - a) * 2;
          let c = dp1[v];
          let e = (sums[v] - c) * 2;
          res = Math.min(res, a + b + c + e);
        }
      }
      {
        res = Math.min(res, 2 * sum - dp[u].reduce((a, b) => a + b, 0));
      }
    }
  };
  dfs1(0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => [0, 0, 0, 0]),
        max = Array.from({
    length: n
  }, () => []);
  const sums = new Array(n).fill(0);
  const dfs = u => {
    let queue = [[u, -1]];
    const p = [];
    const d = new Array(n).fill(0);
    for (let [u, from] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        p[v] = [u, i];
        d[u]++;
        queue.push([v, i]);
      }
    }
    {
      let queue = [];
      for (let i = 0; i < n; i++) {
        if (!d[i]) {
          queue.push(i);
        }
      }
      for (let v of queue) {
        if (!p[v]) continue;
        const [u, i] = p[v];
        let ans = dp[v][0] + w[i];
        if (dp[u][0] <= ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = dp[u][1];
          dp[u][1] = dp[u][0];
          dp[u][0] = ans;
          max[u][1] = max[u][0];
          max[u][0] = v;
        } else if (dp[u][1] <= ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = dp[u][1];
          dp[u][1] = ans;
          max[u][1] = v;
        } else if (dp[u][2] < ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = ans;
        } else if (dp[u][3] < ans) {
          dp[u][3] = ans;
        }
        sums[u] += sums[v] + w[i];
        d[u]--;
        if (!d[u]) queue.push(u);
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = u => {
    const queue = [[u, -1, 0]];
    for (let [u, from, d] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        let nd = d;
        if (max[u][0] === v) {
          nd = Math.max(d, dp[u][1]);
        } else {
          nd = Math.max(d, dp[u][0]);
        }
        queue.push([v, i, nd + w[i]]);
        {
          let arr = [...dp[u]];
          if (max[u][0] === v) arr[0] = d;else if (max[u][1] === v) arr[1] = d;else arr[2] = d;
          arr.sort((a, b) => b - a);
          let a = arr[0] + arr[1];
          let b = (sum - sums[v] - w[i] - a) * 2;
          let c = dp[v][0] + dp[v][1];
          let e = (sums[v] - c) * 2;
          res = Math.min(res, a + b + c + e);
        }
        {
          let a = [...dp[u], d].sort((a, b) => b - a);
          a.pop();
          res = Math.min(res, 2 * sum - a.reduce((a, b) => a + b, 0));
        }
      }
    }
  };
  dfs1(0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => [0, 0, 0, 0]),
        max = Array.from({
    length: n
  }, () => []);
  const sums = new Array(n).fill(0);
  const dfs = u => {
    let queue = [[u, -1]];
    const p = [];
    const d = new Array(n).fill(0);
    for (let [u, from] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        p[v] = [u, i];
        d[u]++;
        queue.push([v, i]);
      }
    }
    {
      let queue = [];
      for (let i = 0; i < n; i++) {
        if (!d[i]) {
          queue.push(i);
        }
      }
      for (let v of queue) {
        if (!p[v]) continue;
        const [u, i] = p[v];
        let ans = dp[v][0] + w[i];
        if (dp[u][0] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = dp[u][0];
          dp[u][0] = ans;
          max[u][1] = max[u][0];
          max[u][0] = v;
        } else if (dp[u][1] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = ans;
          max[u][1] = v;
        } else if (dp[u][2] < ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = ans;
        } else if (dp[u][3] < ans) {
          dp[u][3] = ans;
        }
        sums[u] += sums[v] + w[i];
        d[u]--;
        if (!d[u]) queue.push(u);
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = u => {
    const queue = [[u, -1, 0]];
    for (let [u, from, d] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        let nd = d;
        if (max[u][0] === v) {
          nd = Math.max(d, dp[u][1]);
        } else {
          nd = Math.max(d, dp[u][0]);
        }
        queue.push([v, i, nd + w[i]]);
        {
          let arr = [...dp[u]];
          if (max[u][0] === v) arr[0] = d;else if (max[u][1] === v) arr[1] = d;else arr[2] = d;
          arr.sort((a, b) => b - a);
          let a = arr[0] + arr[1];
          let b = (sum - sums[v] - w[i] - a) * 2;
          let c = dp[v][0] + dp[v][1];
          let e = (sums[v] - c) * 2;
          res = Math.min(res, a + b + c + e);
        }
        {
          let a = [...dp[u], d].sort((a, b) => b - a);
          a.pop();
          res = Math.min(res, 2 * sum - a.reduce((a, b) => a + b, 0));
        }
      }
    }
  };
  dfs1(0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => [0, 0, 0, 0]),
        max = Array.from({
    length: n
  }, () => []);
  const sums = new Array(n).fill(0);
  const dfs = u => {
    let queue = [[u, -1]];
    const p = [];
    const d = new Array(n).fill(0);
    for (let [u, from] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        p[v] = [u, i];
        d[u]++;
        queue.push([v, i]);
      }
    }
    {
      let queue = [];
      for (let i = 0; i < n; i++) {
        if (!d[i]) {
          queue.push(i);
        }
      }
      for (let v of queue) {
        if (!p[v]) continue;
        const [u, i] = p[v];
        let ans = dp[v][0] + w[i];
        if (dp[u][0] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = dp[u][0];
          dp[u][0] = ans;
          max[u][1] = max[u][0];
          max[u][0] = v;
        } else if (dp[u][1] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = ans;
          max[u][1] = v;
        } else if (dp[u][2] < ans) {
          dp[u][3] = dp[u][2];
          dp[u][2] = ans;
        } else if (dp[u][3] < ans) {
          dp[u][3] = ans;
        }
        sums[u] += sums[v] + w[i];
        d[u]--;
        if (!d[u]) queue.push(u);
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = u => {
    const queue = [[u, -1, 0]];
    for (let [u, from, d] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        let nd = d;
        if (max[u][0] === v) {
          nd = Math.max(d, dp[u][1]);
        } else {
          nd = Math.max(d, dp[u][0]);
        }
        queue.push([v, i, nd + w[i]]);
        {
          let a = d;
          if (max[u][0] === v) a += dp[u][1];else a += dp[u][0];
          if (from === -1) {
            if (v === max[u][0] || v === max[u][1]) {
              a += dp[u][2];
            } else {
              a += dp[u][1];
            }
          }
          let b = (sum - sums[v] - w[i] - a) * 2;
          let c = dp[v][0] + dp[v][1];
          let e = (sums[v] - c) * 2;
          res = Math.min(res, a + b + c + e);
        }
        {
          let a = [...dp[u], d].sort((a, b) => b - a);
          a.pop();
          res = Math.min(res, 2 * sum - a.reduce((a, b) => a + b, 0));
        }
      }
    }
  };
  dfs1(0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => [0, 0, 0]),
        max = Array.from({
    length: n
  }, () => []);
  dp[0] = [0, 0, 0, 0];
  const sums = new Array(n).fill(0);
  const dfs = u => {
    let queue = [[u, -1]];
    const p = [];
    const d = new Array(n).fill(0);
    for (let [u, from] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        p[v] = [u, i];
        d[u]++;
        queue.push([v, i]);
      }
    }
    {
      let queue = [];
      for (let i = 0; i < n; i++) {
        if (!d[i]) {
          queue.push(i);
        }
      }
      for (let v of queue) {
        if (!p[v]) continue;
        const [u, i] = p[v];
        let ans = dp[v][0] + w[i];
        if (dp[u][0] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = dp[u][0];
          dp[u][0] = ans;
          max[u][1] = max[u][0];
          max[u][0] = v;
        } else if (dp[u][1] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = ans;
          max[u][1] = v;
        } else if (dp[u][2] < ans) {
          dp[u][2] = ans;
        } else if (u === 0 && dp[u][3] < ans) {
          dp[u][3] = ans;
        }
        sums[u] += sums[v] + w[i];
        d[u]--;
        if (!d[u]) queue.push(u);
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = u => {
    const queue = [[u, -1, 0]];
    for (let [u, from, d] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        let nd = d;
        if (max[u][0] === v) {
          nd = Math.max(d, dp[u][1]);
        } else {
          nd = Math.max(d, dp[u][0]);
        }
        queue.push([v, i, nd + w[i]]);
        {
          let a = d;
          if (max[u][0] === v) a += dp[u][1];else a += dp[u][0];
          if (from === -1) {
            if (v === max[u][0] || v === max[u][1]) {
              a += dp[u][2];
            } else {
              a += dp[u][1];
            }
          }
          let b = (sum - sums[v] - w[i] - a) * 2;
          let c = dp[v][0] + dp[v][1];
          let e = (sums[v] - c) * 2;
          res = Math.min(res, a + b + c + e);
        }
        {
          let a = d + dp[u][0] + dp[u][1] + dp[u][2];
          if (from === -1) a += dp[u][3];
          res = Math.min(res, 2 * sum - a);
        }
      }
    }
  };
  dfs1(0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => [0, 0, 0]),
        max = Array.from({
    length: n
  }, () => []);
  const fa = new Array(n);
  fa[0] = -1;
  const sums = new Array(n).fill(0);
  const dfs = u => {
    let queue = [[u, -1]];
    const p = [];
    const d = new Array(n).fill(0);
    for (let [u, from] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        p[v] = [u, i];
        d[u]++;
        queue.push([v, i]);
      }
    }
    {
      let queue = [];
      for (let i = 0; i < n; i++) {
        if (!d[i]) {
          queue.push(i);
          dp[u] = [0, 0, 0];
        }
      }
      for (let v of queue) {
        if (!p[v]) continue;
        const [u, i] = p[v];
        let ans = dp[v][0] + w[i];
        if (dp[u][0] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = dp[u][0];
          dp[u][0] = ans;
          max[u][1] = max[u][0];
          max[u][0] = v;
        } else if (dp[u][1] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = ans;
          max[u][1] = v;
        } else if (dp[u][2] < ans) {
          dp[u][2] = ans;
        }
        sums[u] += sums[v] + w[i];
        d[u]--;
        if (!d[u]) queue.push(u);
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = u => {
    const queue = [[u, -1, 0]];
    for (let [u, from, d] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        let nd = d;
        if (max[u][0] === v) {
          nd = Math.max(d, dp[u][1]);
        } else {
          nd = Math.max(d, dp[u][0]);
        }
        queue.push([v, i, nd + w[i]]);
        {
          let a = d;
          if (max[u][0] === v) a += dp[u][1];else a += dp[u][0];
          if (from === -1) {
            if (v === max[u][0] || v === max[u][1]) {
              a += dp[u][2];
            } else {
              a += dp[u][1];
            }
          }
          let b = (sum - sums[v] - w[i] - a) * 2;
          let c = dp[v][0] + dp[v][1];
          let e = (sums[v] - c) * 2;
          res = Math.min(res, a + b + c + e);
        }
      }
    }
  };
  dfs1(0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => [0, 0, 0]),
        max = Array.from({
    length: n
  }, () => []);
  const fa = new Array(n);
  fa[0] = -1;
  const p = [];
  const d = new Array(n).fill(0);
  const sums = new Array(n).fill(0);
  const dfs = u => {
    let queue = [[u, -1]];
    for (let [u, from] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        p[v] = [u, i];
        d[u]++;
        queue.push([v, i]);
      }
    }
    {
      const tmp = [...d];
      let queue = [];
      for (let i = 0; i < n; i++) {
        if (!tmp[i]) {
          queue.push(i);
          dp[u] = [0, 0, 0];
        }
      }
      for (let v of queue) {
        if (!p[v]) continue;
        const [u, i] = p[v];
        let ans = dp[v][0] + w[i];
        if (dp[u][0] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = dp[u][0];
          dp[u][0] = ans;
          max[u][1] = max[u][0];
          max[u][0] = v;
        } else if (dp[u][1] <= ans) {
          dp[u][2] = dp[u][1];
          dp[u][1] = ans;
          max[u][1] = v;
        } else if (dp[u][2] < ans) {
          dp[u][2] = ans;
        }
        sums[u] += sums[v] + w[i];
        tmp[u]--;
        if (!tmp[u]) queue.push(u);
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = u => {
    const queue = [[u, -1, 0]];
    for (let [u, from, d] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (from ^ 1)) continue;
        const v = e[i];
        let nd = d;
        if (max[u][0] === v) {
          nd = Math.max(d, dp[u][1]);
        } else {
          nd = Math.max(d, dp[u][0]);
        }
        {
          let a = d;
          if (max[u][0] === v) a += dp[u][1];else a += dp[u][0];
          if (fa[u] === -1) {
            if (v === max[u][0] || v === max[u][1]) {
              a += dp[u][2];
            } else {
              a += dp[u][1];
            }
          }
          let b = (sum - sums[v] - w[i] - a) * 2;
          let c = dp[v][0] + dp[v][1];
          let e = (sums[v] - c) * 2;
          res = Math.min(res, a + b + c + e);
        }
        queue.push([v, i, nd + w[i]]);
      }
    }
  };
  dfs1(0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => []),
        max = Array.from({
    length: n
  }, () => []);
  const fa = new Array(n);
  fa[0] = -1;
  const dfs = u => {
    dp[u] = [0, 0, 0];
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = e[i];
      if (v === fa[u]) continue;
      fa[v] = u;
      dfs(v);
      let ans = dp[v][0] + w[i];
      if (dp[u][0] <= ans) {
        dp[u][2] = dp[u][1];
        dp[u][1] = dp[u][0];
        dp[u][0] = ans;
        max[u][1] = max[u][0];
        max[u][0] = v;
      } else if (dp[u][1] <= ans) {
        dp[u][2] = dp[u][1];
        dp[u][1] = ans;
        max[u][1] = v;
      } else if (dp[u][2] < ans) {
        dp[u][2] = ans;
      }
    }
  };
  dfs(0);
  let res = Infinity;
  const dfs1 = (u, d) => {
    let ans = 0;
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = e[i];
      if (v === fa[u]) continue;
      let nd = d;
      if (max[u][0] === v) {
        nd = Math.max(d, dp[u][1]);
      } else {
        nd = Math.max(d, dp[u][0]);
      }
      let tmp = dfs1(v, nd + w[i]);
      {
        let a = d;
        if (max[u][0] === v) a += dp[u][1];else a += dp[u][0];
        if (fa[u] === -1) {
          if (v === max[u][0] || v === max[u][1]) {
            a += dp[u][2];
          } else {
            a += dp[u][1];
          }
        }
        let b = (sum - tmp - w[i] - a) * 2;
        let c = dp[v][0] + dp[v][1];
        let e = (tmp - c) * 2;
        res = Math.min(res, a + b + c + e);
      }
      ans += tmp + w[i];
    }
    return ans;
  };
  dfs1(0, -1);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => []),
        max = Array.from({
    length: n
  }, () => []);
  const dfs = (u, p) => {
    dp[u] = [0, 0, 0];
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = e[i];
      if (v === p) continue;
      dfs(v, u);
      let ans = dp[v][0] + w[i];
      if (dp[u][0] <= ans) {
        dp[u][2] = dp[u][1];
        dp[u][1] = dp[u][0];
        dp[u][0] = ans;
        max[u][1] = max[u][0];
        max[u][0] = v;
      } else if (dp[u][1] <= ans) {
        dp[u][2] = dp[u][1];
        dp[u][1] = ans;
        max[u][1] = v;
      } else if (dp[u][2] < ans) {
        dp[u][2] = ans;
      }
    }
  };
  dfs(0, -1);
  let res = Infinity;
  const dfs1 = (u, p, d) => {
    let ans = 0;
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = e[i];
      if (v === p) continue;
      let nd = d;
      if (max[u][0] === v) {
        nd = Math.max(d, dp[u][1]);
      } else {
        nd = Math.max(d, dp[u][0]);
      }
      let tmp = dfs1(v, u, nd + w[i]);
      {
        let a = d;
        if (max[u][0] === v) a += dp[u][1];else a += dp[u][0];
        if (p === -1) {
          if (v === max[u][0] || v === max[u][1]) {
            a += dp[u][2];
          } else {
            a += dp[u][1];
          }
        }
        let b = (sum - tmp - w[i] - a) * 2;
        let c = dp[v][0];
        let e = (tmp - c) * 2;
        res = Math.min(res, a + b + c + e);
      }
      ans += tmp + w[i];
    }
    return ans;
  };
  dfs1(0, -1, 0);
  return res === Infinity ? 0 : res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  let sum = 0;
  for (let i = 0; i < n - 1; i++) {
    const [x, y, z] = await rns();
    add(x - 1, y - 1, z);
    add(y - 1, x - 1, z);
    sum += z;
  }
  const dp = Array.from({
    length: n
  }, () => []),
        max = Array.from({
    length: n
  }, () => []);
  const dfs = (u, p) => {
    dp[u] = [0, 0, 0];
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = e[i];
      if (v === p) continue;
      dfs(v, u);
      let ans = dp[v][0] + w[i];
      if (dp[u][0] <= ans) {
        dp[u][2] = dp[u][1];
        dp[u][1] = dp[u][0];
        dp[u][0] = ans;
        max[u][1] = max[u][0];
        max[u][0] = v;
      } else if (dp[u][1] <= ans) {
        dp[u][2] = dp[u][1];
        dp[u][1] = ans;
        max[u][1] = v;
      } else if (dp[u][2] < ans) {
        dp[u][2] = ans;
      }
    }
  };
  dfs(0, -1);
  let res = Infinity;
  const dfs1 = (u, p, d) => {
    let ans = 0;
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = e[i];
      if (v === p) continue;
      let nd = d;
      if (max[u][0] === v) {
        nd = Math.max(d, dp[u][1]);
      } else {
        nd = Math.max(d, dp[u][0]);
      }
      let tmp = dfs1(v, u, nd + w[i]);
      {
        let a = d;
        if (max[u][0] === v) a += dp[u][1];else a += dp[u][0];
        if (p === -1) {
          if (v === max[u][0] || v === max[u][1]) {
            a += dp[u][2];
          } else {
            a += dp[u][1];
          }
        }
        let b = (sum - tmp - w[i] - a) * 2;
        let c = dp[v][0];
        let e = (tmp - c) * 2;
        res = Math.min(res, a + b + c + e);
      }
      ans += tmp + w[i];
    }
    return ans;
  };
  dfs1(0, -1, 0);
  return res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();


Luis has a sequence of $$$n+1$$$ integers $$$a_1, a_2, \ldots, a_{n+1}$$$. For each $$$i = 1, 2, \ldots, n+1$$$ it is guaranteed that $$$0\leq a_i < n$$$, or $$$a_i=n^2$$$. He has calculated the sum of all the elements of the sequence, and called this value $$$s$$$. Luis has lost his sequence, but he remembers the values of $$$n$$$ and $$$s$$$. Can you find the number of elements in the sequence that are equal to $$$n^2$$$?We can show that the answer is unique under the given constraints.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$n$$$ and $$$s$$$ ($$$1\le n< 10^6$$$, $$$0\le s \le 10^{18}$$$). It is guaranteed that the value of $$$s$$$ is a valid sum for some sequence satisfying the above constraints.

For each test case, print one integer — the number of elements in the sequence which are equal to $$$n^2$$$.

NoteIn the first test case, we have $$$s=0$$$ so all numbers are equal to $$$0$$$ and there isn't any number equal to $$$49$$$.In the second test case, we have $$$s=1$$$. There are two possible sequences: $$$[0, 1]$$$ or $$$[1, 0]$$$. In both cases, the number $$$1$$$ appears just once. In the third test case, we have $$$s=12$$$, which is the maximum possible value of $$$s$$$ for this case. Thus, the number $$$4$$$ appears $$$3$$$ times in the sequence.

'use strict';
const { throws } = require('assert');

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const MOD = 1e9+7;

const calc = (n, s)=>{
  n = BigInt(n);
  s = BigInt(s)
  return (s/(n*n)).toString(10)
};

function main() {
    let T = +readline()
    while (T--){
      let [n, s] = readline().split(' ');
      print(calc(n, s));
    }
}

E.calc = calc;

let buf='';

process.stdin.on('readable', function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end', function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let [n,s]=line[_].split(' ');
        n=BigInt(n);
        s=BigInt(s);
        n=n*n;
        // console.log(s,n);
        let ans=''+s/n;
        console.log(ans);
    }
})

'use strict';
const { throws } = require('assert');

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const EPS = 1e-6;
const MOD = 1e9+7;

const calc = (n, s)=>{
  return Math.floor(s/(n*n)+EPS)
};

function main() {
    let T = +readline()
    while (T--){
      let [n, s] = ra();
      print(calc(n, s));
    }
}

E.calc = calc;

'use strict';
const { throws } = require('assert');

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const EPS = 1e-6;
const MOD = 1e9+7;

const calc = (n, s)=>{
  return Math.floor(s/(n*n))
};

function main() {
    let T = +readline()
    while (T--){
      let [n, s] = ra();
      print(calc(n, s));
    }
}

E.calc = calc;


You are standing on the $$$\mathit{OX}$$$-axis at point $$$0$$$ and you want to move to an integer point $$$x > 0$$$.You can make several jumps. Suppose you're currently at point $$$y$$$ ($$$y$$$ may be negative) and jump for the $$$k$$$-th time. You can:   either jump to the point $$$y + k$$$  or jump to the point $$$y - 1$$$. What is the minimum number of jumps you need to reach the point $$$x$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains the single integer $$$x$$$ ($$$1 \le x \le 10^6$$$) — the destination point.

For each test case, print the single integer — the minimum number of jumps to reach $$$x$$$. It can be proved that we can reach any integer point $$$x$$$.

NoteIn the first test case $$$x = 1$$$, so you need only one jump: the $$$1$$$-st jump from $$$0$$$ to $$$0 + 1 = 1$$$.In the second test case $$$x = 2$$$. You need at least three jumps:   the $$$1$$$-st jump from $$$0$$$ to $$$0 + 1 = 1$$$;  the $$$2$$$-nd jump from $$$1$$$ to $$$1 + 2 = 3$$$;  the $$$3$$$-rd jump from $$$3$$$ to $$$3 - 1 = 2$$$; Two jumps are not enough because these are the only possible variants:   the $$$1$$$-st jump as $$$-1$$$ and the $$$2$$$-nd one as $$$-1$$$ — you'll reach $$$0 -1 -1 =-2$$$;  the $$$1$$$-st jump as $$$-1$$$ and the $$$2$$$-nd one as $$$+2$$$ — you'll reach $$$0 -1 +2 = 1$$$;  the $$$1$$$-st jump as $$$+1$$$ and the $$$2$$$-nd one as $$$-1$$$ — you'll reach $$$0 +1 -1 = 0$$$;  the $$$1$$$-st jump as $$$+1$$$ and the $$$2$$$-nd one as $$$+2$$$ — you'll reach $$$0 +1 +2 = 3$$$; In the third test case, you need two jumps: the $$$1$$$-st one as $$$+1$$$ and the $$$2$$$-nd one as $$$+2$$$, so $$$0 + 1 + 2 = 3$$$.In the fourth test case, you need three jumps: the $$$1$$$-st one as $$$-1$$$, the $$$2$$$-nd one as $$$+2$$$ and the $$$3$$$-rd one as $$$+3$$$, so $$$0 - 1 + 2 + 3 = 4$$$.

'use strict'

let t = readline();

while(t--)
{
    let x = readline(), s = 0, a = [], c = 0;
    for(let i = 1; s < x; i++)
    {
        s+=i;
        c++;
    }
    if(s!=x)
        {
            if(!(s - x - 1))while(s!=x){s--; c++;}
        }
    print(c);
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var y = 0;
  var res = 0;

  for (var k = 1; k <= l; k++) {
    y += k;
    res++;

    if (y == l) {
      break;
    } else if (y > l) {
      if (y - l == 1) {
        res++;
      }
      break;
    }
  }

  print(res);
}

var tc = parseInt(readline());
for (; tc--;) {
    var Ar = readline().split(' ').map(x => +x);
    var n = Ar[0];
    var res = 0;
    var c = 0, x = 1;
    while (res < n) {
        res += x;
        x++, c++;
    }
    print(n == res - 1 ? c + 1 : c);
}

const solve = (x) => {
    let jump = 0;
    while (x > 0) {
        jump++;
        x -= jump;
    }
    if (x == -1) jump++;
    console.log(jump);
};

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

main()

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const n = +readLine();
    let [i, count] = [1, 0];
    while (count < n) {
      count += i;
      i++;
    }
    if (count === n) console.log(i - 1);
    else if (count - n > 1) console.log(i - 1);
    else console.log(i);
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function 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){outputList.push(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 t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();

		var index = 0;
		var count = 1;
		while(N > index){
			index += count;
			count++;
		}
		count--;

		if(index - 1 == N){
			count++;
		}
		myout(count);
	}
}

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

  let i = 1;
  let t = 0;
  readline.on('line', line => {
    if (i == 1) {
        // number of test case
        t = parseInt(line)
        i++;
    } else if (i <= t) {
        solve(line)
        i++;
    } else {
        solve(line)
        readline.close()
    }
  });

  function solve(input) {
    // your code here
    let x = parseInt(input);
    let i1 = 1
    let x1 = 1
    while (x1 < x) {
        i1 += 1
        x1 += i1
    }

    if (x1 - x == 1) console.log(i1 + 1)
    else console.log(i1)
  }

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let s=0;s<t;++s){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const s=n(r(747));let i="",o=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(o=s.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),s.default.writeFileSync("output.txt",l),console.log(l),s.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{i+=t})),process.stdin.on("end",(e=>{o=i.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function h(){return o[u++]}function f(){return h().split(" ").map((t=>parseFloat(t)))}function c(){return h().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const s=n(r(312));s.default.runEachTest((function(){let[t]=s.default.nextNumbers(),e=1,r=1;for(;e<t;)r++,e+=r;e!=t?e-1!=t?s.default.puts(r):s.default.puts(r+1):s.default.puts(r)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//
//   let a = 1
//
//   let i = 1
//   while (a < n) {
//     i++
//     a += i
//   }
//
//   if (a == n) {
//     io.puts(i)
//     return
//   }
//
//   if (a - 1 == n) {
//     io.puts(i + 1)
//     return
//   }
//
//   io.puts(i)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

/*
 * File Created: Monday, 30th November 2020 3:31:00 pm
 * Author: Lukas Rimkus
 */

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const n = parseInt(data.shift());

        const res = b(n);

        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(num)
{
    return num.length ;
}

function b(goal)
{

    function jump1(y,k)
    {
        return y + k;
    }
    function jump2(y)
    {
        return y - 1;
    }

    let sum = 0;

    let jumps = 0;

    let arr = [];

    while(sum < goal)
    {
        jumps++;

        arr.push(jumps);

        sum = sum + jumps;
    }

    if(sum === goal)
    {
        return arr.length;
    }
    else
    {
        let current_pos = sum;

        // that's how many steps back;
        let diference = current_pos - goal;

        // console.log(arr, arr.length, sum, diference)

        for(let i = 0 ; i < arr.length; i++)
        {
            if((arr[i] + 1) === diference)
            {
                return arr.length;
            }
        }
       return arr.length + 1;
    }
}

module.exports = b;

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const x = readline();
  var answer = []

  var array = []

  array[0] = 0
  array[1] = 1
  array[2] = 3
  array[3] = 2
  var index = 0
  for (var i = 0; i < 100000; i++) {
    if (index > 10000000) break
    index = index + i
    array[index] = i
  }

  Array(Number(x)).fill(1).map((t, i) => {

    var line = readline();
    var x = Number(line)
    var xx = x
    var value1 = 0
    var value2 = 0
    if (array[x]) return console.log(array[x])
    if (array[x+1]) return console.log(array[x+1]+1)
    while (!array[x]) {
      x -= 1
    }
    console.log(array[x] +1)

    // console.log(array[x] + 1)
  })
  // console.log(array)
  // array.map((v, i) => {
  //   console.log({v, i})
  // })
}

'use strict'

let t = readline();

while(t--)
{
    let x = readline(), s = 0, a = [], c = 0;
    for(let i = 1; s < x; i++)
    {
        s+=i;
        c++;
    }
    for(let i = 1; s - i > x; i++)
    {
        s-=i;
        c--;
    }
    while(s>x)
    {
        s--;
        c++;
    }
    print(c);
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var y = 0;
  var res = 0;

  for (var k = 1; k <= l; k++) {
    y += k;
    res++;

    if (y == l) {
      break;
    } else if (l - y == 1) {
      res += 2;
      break;
    } else {
      res = l - y;
      break;
    }
  }

  print(res);
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var p = 0;
  var res = 0;

  if (l == 1) {
    print(l);
  } else if (l == 2) {
    print(l+1);
  } else {
    print(l-1);
  }
}

const solve = (x) => {
    if (x == 1) {
        console.log(1);
        return;
    }
    if (x == 2) {
        console.log(3);
        return;
    }
    console.log(x - 1);
};

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

main()

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const n = +readLine();
    if (n === 1) console.log(1);
    else if (n === 2) console.log(3);
    else {
      let [i, count, found] = [1, 0, false];
      while (count <= n) {
        count += i;
        if (count === n) {
          console.log(i);
          found = true;
          break;
        }
        if (count > n) break;
        i++;
      }
      if (!found) {
        const prev = count - i;
        const [prevDiff, nextDiff] = [Math.abs(prev - n), Math.abs(count - n)];
        if (prevDiff <= nextDiff) {
          console.log(i - 1 + prevDiff);
        } else {
          console.log(i + nextDiff);
        }
      }
    }
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function 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){outputList.push(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 t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var index = 0;
		var count = 1;
		while(N > index){
			index += count;
			count++;
		}
		count--;
		if(N != index && N % 2 != index % 2){
			count++;
		}

		myout(count);
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function 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){outputList.push(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 max = 1000007;
	var dp = new Array(max);
	dp[0] = 0;
	var index = 0;
	var count = 1;
	while(index < max){
		index += count;
		dp[index] = count;
		count++;
	}
	var add = 1;
	while(true){
		var index = 1;
		var count = 1 + add;
		while(index < max){
			index += count;
			if(dp[index] == null){
				dp[index] = count;
			}else{
				dp[index] = Math.min(count, dp[index]);
			}
			count++;
		}
		add++;
		if(add > max){
			break;
		}
	}
	for(var i = max; i >= 1; i--){
		if(dp[i] != null){
			if(dp[i - 1] == null){
				dp[i - 1] = dp[i] + 1;
			}else{
				dp[i - 1] = Math.min(dp[i] + 1, dp[i - 1]);
			}
		}
	}
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		myout(dp[N]);
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function 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){outputList.push(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 max = 1500007;
	var dp = new Array(max);
	dp[0] = 0;
	var index = 0;
	var count = 1;
	while(index < max){
		index += count;
		dp[index] = count;
		count++;
	}
	var add = 1;
	while(true){
		var index = 1;
		var count = 1 + add;
		while(index < max){
			index += count;
			if(dp[index] == null){
				dp[index] = count;
			}else{
				dp[index] = Math.min(count, dp[index]);
			}
			count++;
		}
		add++;
		if(add > max){
			break;
		}
	}
	for(var i = max; i >= 1; i--){
		if(dp[i] != null){
			if(dp[i - 1] == null){
				dp[i - 1] = dp[i] + 1;
			}else{
				dp[i - 1] = Math.min(dp[i] + 1, dp[i - 1]);
			}
		}
	}
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		myout(dp[N]);
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function 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){outputList.push(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 dp = new Array(1000000);
	dp[0] = 0;
	var index = 0;
	var count = 1;
	while(index < 1000000){
		index += count;
		dp[index] = count;
		count++;
	}
	var add = 1;
	while(true){
		var index = 1;
		var count = 1 + add;
		while(index < 1000000){
			index += count;
			if(dp[index] == null){
				dp[index] = count;
			}else{
				dp[index] = Math.min(count, dp[index]);
			}
			count++;
		}
		add++;
		if(add > 1000000){
			break;
		}
	}

	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		if(dp[N] == null){
			myout(dp[N + 1] + 1);
		}else{
			myout(dp[N]);
		}

	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const x = readline();
  var answer = []

  var array = []

  array[0] = 0
  array[1] = 1
  array[2] = 3
  array[3] = 2
  var index = 0
  for (var i = 0; i < 100000; i++) {
    if (index > 10000000) break
    index = index + i
    array[index] = i
  }

  Array(Number(x)).fill(1).map((t, i) => {

    var line = readline();
    var x = Number(line)
    var xx = x
    var value1 = 0
    var value2 = 0
    if (array[x]) return console.log(array[x])
    while (!array[x]) {
      x -= 1
      value1 += 1
    }
    while (!array[xx]) {
      xx += 1
      value2 += 1
    }
    console.log(Math.min(array[x] + value1, array[xx] + value2 ))

    // console.log(array[x] + 1)
  })
  // console.log(array)
  // array.map((v, i) => {
  //   console.log({v, i})
  // })
}


Mark is cleaning a row of $$$n$$$ rooms. The $$$i$$$-th room has a nonnegative dust level $$$a_i$$$. He has a magical cleaning machine that can do the following three-step operation.   Select two indices $$$i<j$$$ such that the dust levels $$$a_i$$$, $$$a_{i+1}$$$, $$$\dots$$$, $$$a_{j-1}$$$ are all strictly greater than $$$0$$$.  Set $$$a_i$$$ to $$$a_i-1$$$.  Set $$$a_j$$$ to $$$a_j+1$$$.  Mark's goal is to make $$$a_1 = a_2 = \ldots = a_{n-1} = 0$$$ so that he can nicely sweep the $$$n$$$-th room. Determine the minimum number of operations needed to reach his goal.

The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$) — the number of rooms. The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0\leq a_i\leq 10^9$$$) — the dust level of each room. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, print a line containing a single integer — the minimum number of operations. It can be proven that there is a sequence of operations that meets the goal.

NoteIn the first case, one possible sequence of operations is as follows.   Choose $$$i=1$$$ and $$$j=2$$$, yielding the array $$$[1,1,0]$$$.  Choose $$$i=1$$$ and $$$j=3$$$, yielding the array $$$[0,1,1]$$$.  Choose $$$i=2$$$ and $$$j=3$$$, yielding the array $$$[0,0,2]$$$.  At this point, $$$a_1=a_2=0$$$, completing the process.In the second case, one possible sequence of operations is as follows.   Choose $$$i=4$$$ and $$$j=5$$$, yielding the array $$$[0,2,0,1,1]$$$.  Choose $$$i=2$$$ and $$$j=3$$$, yielding the array $$$[0,1,1,1,1]$$$.  Choose $$$i=2$$$ and $$$j=5$$$, yielding the array $$$[0,0,1,1,2]$$$.  Choose $$$i=3$$$ and $$$j=5$$$, yielding the array $$$[0,0,0,1,3]$$$.  Choose $$$i=4$$$ and $$$j=5$$$, yielding the array $$$[0,0,0,0,4]$$$. In the last case, the array already satisfies the condition.

function dustSweeper() {
  n = +r();
  a = r().split` `.map(Number);
  let firstNumberIndex = a.indexOf(a.find(d => d > 0));
  if (firstNumberIndex === -1) {
    log(0);
    return;
  }
  let sum = 0;
  for (let i = firstNumberIndex; i < a.length - 1; i++) {
    if (a[i] === 0) sum++;
    else sum += a[i];
  }
  log(sum);
}

function main() {
  tt = +r();
  for (; tt; tt--) dustSweeper();
}

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

r = readline;
log = console.log;

'use strict';
/*
3
2 0 0
5
0 2 0 2 0
6
2 0 3 0 4 6
4
0 0 0 10
*/
const main = () => {
  const n = parseInt(readline());

  for (let i = 0; i < n; ++i) {
    const len = parseInt(readline());
    const arr = readline().split(' ').map(Number);
    let operations = 0;
    let sum = 0;
    let seenNonZero = false;
    for (let i = 0; i < len - 1; ++i) {
      if (arr[i] === 0 && seenNonZero) {
        ++operations;
      } else if (arr[i] > 0) {
        seenNonZero = true;
      }
      sum += arr[i];
    }
    console.log(operations + sum);
  }
};

const readline = () => {
  return inputString[currentLine++];
};

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let flag = false,
      zc = 0;
    for (let i = 0; i < n - 1; i++) {
      if (arr[i] === 0 && flag) zc++;
      else if (arr[i] > 0) flag = true;
    }
    if (!flag) console.log(0);
    else {
      let sum = 0;
      for (let i = 0; i < n - 1; i++) sum += arr[i];
      console.log(sum + zc);
    }
  }
};
solve();

var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var n = parseInt(readline());
        var arr = readline().split(' ').map(x=>parseInt(x));
        var sum = 0;
        var tail = 0;
        while (arr[tail] != undefined && arr[tail] == 0) {
            tail++;
        }
        for (var i = tail+1; i < n-1; i++) {
            if (arr[i] == 0) {
                arr[tail]--;
                arr[i]++;
                if (arr[tail] == 0) {
                    tail++;
                }
                sum++;
            }
        }
        for (var i = 0; i < n-1; i++) {
            sum += arr[i];
        }
        print(sum);
    }

function dustSweeper() {
  n = +r();
  a = r().split` `.map(Number);
  let firstNumberIndex = a.indexOf(a.find(d => d > 0));
  let sum = 0;
  for (let i = firstNumberIndex; i < a.length - 1; i++) {
    if (a[i] === 0) sum++;
    else sum += a[i];
  }
  log(sum);

  // function firstZeroIndex(i) {
  //   let firstZeroIndex = a.slice(i + 1).indexOf(0);
  //   if (firstZeroIndex === -1) return -1;
  //   return firstZeroIndex + i + 1;
  // }

  // for (let i = 0; i < a.length && firstZeroIndex(i) !== -1; i++) {
  //   while (a[i] > 0 || firstZeroIndex(i) !== -1) {
  //     // log(`before: i:${i}, a=${a}`);
  //     i0 = firstZeroIndex(i);
  //     a[i0]++;
  //     a[i]--;
  //     count++;
  //     // log(`after: i:${i}, a=${a}`);
  //   }
  // }
}

function main() {
  tt = +r();
  for (; tt; tt--) dustSweeper();
}

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

r = readline;
log = console.log;

function dustSweeper() {
  n = +r();
  a = r().split` `.map(Number);
  let firstNumberIndex = a.indexOf(a.find(d => d > 0));
  // a = a.slice(firstNumberIndex);
  let count = 0;
  for (let i = firstNumberIndex; i < a.length - 1; i++) {
    if (a[i] === 0) count++;
  }
  log(count + a.reduce((p, c, i) => (i < a.length - 1 ? p + c : p)));

  // function firstZeroIndex(i) {
  //   let firstZeroIndex = a.slice(i + 1).indexOf(0);
  //   if (firstZeroIndex === -1) return -1;
  //   return firstZeroIndex + i + 1;
  // }

  // for (let i = 0; i < a.length && firstZeroIndex(i) !== -1; i++) {
  //   while (a[i] > 0 || firstZeroIndex(i) !== -1) {
  //     // log(`before: i:${i}, a=${a}`);
  //     i0 = firstZeroIndex(i);
  //     a[i0]++;
  //     a[i]--;
  //     count++;
  //     // log(`after: i:${i}, a=${a}`);
  //   }
  // }
}

function main() {
  tt = +r();
  for (; tt; tt--) dustSweeper();
}

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

r = readline;
log = console.log;


A club plans to hold a party and will invite some of its $$$n$$$ members. The $$$n$$$ members are identified by the numbers $$$1, 2, \dots, n$$$. If member $$$i$$$ is not invited, the party will gain an unhappiness value of $$$a_i$$$.There are $$$m$$$ pairs of friends among the $$$n$$$ members. As per tradition, if both people from a friend pair are invited, they will share a cake at the party. The total number of cakes eaten will be equal to the number of pairs of friends such that both members have been invited.However, the club's oven can only cook two cakes at a time. So, the club demands that the total number of cakes eaten is an even number.What is the minimum possible total unhappiness value of the party, respecting the constraint that the total number of cakes eaten is even?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^4$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^5$$$, $$$0 \leq m \leq \min(10^5,\frac{n(n-1)}{2})$$$) — the number of club members and pairs of friends. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2, \dots,a_n$$$ ($$$0 \leq a_i \leq 10^4$$$) — the unhappiness value array. Each of the next $$$m$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x,y \leq n$$$, $$$x \neq y$$$) indicating that $$$x$$$ and $$$y$$$ are friends. Each unordered pair $$$(x,y)$$$ appears at most once in each test case. It is guaranteed that both the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases do not exceed $$$10^5$$$.

For each test case, print a line containing a single integer – the minimum possible unhappiness value of a valid party.

NoteIn the first test case, all members can be invited. So the unhappiness value is $$$0$$$.In the second test case, the following options are possible:   invite $$$1$$$ and $$$2$$$ ($$$0$$$ cakes eaten, unhappiness value equal to $$$3$$$);  invite $$$2$$$ and $$$3$$$ ($$$0$$$ cakes eaten, unhappiness value equal to $$$2$$$);  invite only $$$1$$$ ($$$0$$$ cakes eaten, unhappiness value equal to $$$4$$$);  invite only $$$2$$$ ($$$0$$$ cakes eaten, unhappiness value equal to $$$5$$$);  invite only $$$3$$$ ($$$0$$$ cakes eaten, unhappiness value equal to $$$3$$$);  invite nobody ($$$0$$$ cakes eaten, unhappiness value equal to $$$6$$$).  The minimum unhappiness value is achieved by inviting $$$2$$$ and $$$3$$$.In the third test case, inviting members $$$3,4,5$$$ generates a valid party with the minimum possible unhappiness value.

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

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

function readNumbersLine() {
    return readline().split(" ").map(el => +el);
}

function solve() {
    let arr = {};
    let arr2 = []

    let [n, m] = readNumbersLine()
    let A = readNumbersLine()

    for (let j = 0; j < m; j++) {
        let [x, y] = readNumbersLine()
        x -= 1
        y -= 1
        if (arr[x]) {
            arr[x].push(y);
        } else {
            arr[x] = [y]
        }

        if (arr[y]) {
            arr[y].push(x);
        } else {
            arr[y] = [x]
        }
        arr2.push(A[x] + A[y]);
    }

    if (m % 2 === 0) {
        print(0)
        return;
    }
    A = A.map((value, index) => [value, index]);
    A.sort((a, b) => a[0] - b[0])
    let condition = true;
    let i = 0
    arr2.sort((a, b) => a - b);
    // console.log(arr2)
    // console.log(arr)
    while (condition) {
        let index = A[i][1]
        if (arr[index] && arr[index].length % 2 === 1) {
            console.log(Math.min(A[i][0], arr2[0]));
            return;
        }
        i += 1
        if (i >= A.length) {
            condition = false
        }
    }

    console.log(arr2[0]);
    return;
}

function main() {
    let k = +readline()
    for (let i = 0; i < k; i++) {
        solve();
    }

}

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

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, m] = iInpArr();
    let arr = iInpArr();
    let pair = [],
      obj = {};
    for (let i = 0; i < n; i++) obj[i + 1] = 0;
    for (let i = 0; i < m; i++) {
      let j = iInpArr();
      pair.push(j);
      obj[j[0]] += 1;
      obj[j[1]] += 1;
    }
    if (m === 0 || m % 2 === 0) {
      console.log(0);
      continue;
    }
    let ans = Infinity;
    for (let i = 0; i < n; i++) {
      if (obj[i + 1] & 1) ans = Math.min(ans, arr[i]);
    }
    for (let i = 0; i < m; i++) {
      if ((obj[pair[i][0]] & 1) === 0 && (obj[pair[i][1]] & 1) === 0)
        ans = Math.min(ans, arr[pair[i][0] - 1] + arr[pair[i][1] - 1]);
    }
    console.log(ans);
  }
};
solve();

var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var nm = readline().split(' ').map(x=>parseInt(x));
        var n = nm[0];
        var m = nm[1];
        var unh = readline().split(' ').map(x=>parseInt(x));
        var graph = {};
        var pairs = [];
        for (var i = 0; i < m; i++) {
            var pair = readline().split(' ').map(x=>parseInt(x));
            pairs.push(pair);
            if (!graph[pair[0]]) {
                graph[pair[0]] = 0;
            }
            graph[pair[0]]++;
            if (!graph[pair[1]]) {
                graph[pair[1]] = 0;
            }
            graph[pair[1]]++;
        }
        //console.log(pairs);
        if (!(m & 1) || n == 1) {
            print(0);
        } else {
            var toCheck = new Set();
            var min = Number.POSITIVE_INFINITY;
            Object.keys(graph).forEach((k) => {
                if (graph[k] & 1) {
                    min = Math.min(unh[k-1], min);
                } else {
                    toCheck.add(parseInt(k));
                }
            })
            //console.log(toCheck);
            for (var i = 0; i < pairs.length; i++) {
                if (toCheck.has(pairs[i][0]) && toCheck.has(pairs[i][1])) {
                    min = Math.min(min, unh[pairs[i][0]-1]+unh[pairs[i][1]-1]);
                }
            }

            print(min);
        }
    }

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

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

function readNumbersLine() {
    return readline().split(" ").map(el => +el);
}

function solve() {
    let arr = {};
    let arr2 = []

    let [n, m] = readNumbersLine()
    let A = readNumbersLine()
    const sum = A.reduce((partialSum, a) => partialSum + a, 0);

    for (let j = 0; j < m; j++) {
        let [x, y] = readNumbersLine()
        x -= 1
        y -= 1
        if (arr[x]) {
            arr[x].push(y);
        } else {
            arr[x] = [y]
        }

        if (arr[y]) {
            arr[y].push(x);
        } else {
            arr[y] = [x]
        }
        arr2.push(A[x] + A[y]);
    }

    if (m % 2 === 0) {
        print(0)
        return;
    }
    A = A.map((value, index) => [value, index]);
    A.sort((a, b) => a[0] - b[0])
    let condition = true;
    let i = 0
    arr2.sort();
    // console.log(A)
    // console.log(arr)
    while (condition) {
        let index = A[i][1]
        if (arr[index] && arr[index].length % 2 === 1) {
            console.log(Math.min(A[i][0], arr2[0]));
            return;
        }
        i += 1
        if (i >= A.length) {
            condition = false
        }
    }

    console.log(arr2[0]);
    return;
}

function main() {
    let k = +readline()
    for (let i = 0; i < k; i++) {
        solve();
    }

}