Dmitry has $$$n$$$ segments of different colors on the coordinate axis $$$Ox$$$. Each segment is characterized by three integers $$$l_i$$$, $$$r_i$$$ and $$$c_i$$$ ($$$1 \le l_i \le r_i \le 10^9, 1 \le c_i \le n$$$), where $$$l_i$$$ and $$$r_i$$$ are are the coordinates of the ends of the $$$i$$$-th segment, and $$$c_i$$$ is its color.Dmitry likes to find the minimum distances between segments. However, he considers pairs of segments of the same color uninteresting. Therefore, he wants to know for each segment the distance from this segment to the nearest differently colored segment.The distance between two segments is the minimum of the distances between a point of the first segment and a point of the second segment. In particular, if the segments intersect, then the distance between them is equal to $$$0$$$.For example, Dmitry has $$$5$$$ segments:     The first segment intersects with the second (and these are segments of different colors), so the answers for them are equal to $$$0$$$.  For the $$$3$$$-rd segment, the nearest segment of a different color is the $$$2$$$-nd segment, the distance to which is equal to $$$2$$$.  For the $$$4$$$-th segment, the nearest segment of a different color is the $$$5$$$-th segment, the distance to which is equal to $$$1$$$.  The $$$5$$$-th segment lies inside the $$$2$$$-nd segment (and these are segments of different colors), so the answers for them are equal to $$$0$$$.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of description of each test case contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of segments. The next $$$n$$$ lines contain descriptions of the segments. Each segment is described by three integers $$$l_i$$$, $$$r_i$$$ and $$$c_i$$$ ($$$1 \le l_i \le r_i \le 10^9, 1 \le c_i \le n$$$) — coordinates of the left and right ends of $$$i$$$-th segment, as well as the color of this segment. It is guaranteed that there are at least $$$2$$$ segments of different colors. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, on a separate line print $$$n$$$ integers, where the $$$i$$$-th number is equal to the distance from the $$$i$$$-th segment to the nearest segment of a different color.

NoteIn the first test case of the first sample there is only one segment of color $$$2$$$, and all other segments have color $$$1$$$. Therefore, for segments of color $$$1$$$, the answer is equal to the distance to the $$$3$$$rd segment, and for $$$3$$$rd one, the answer is equal to the minimum of the distances to segments of color $$$1$$$.In the second test case of the first sample there are only $$$2$$$ segments, and for both of them the answer is equal to the distance between them.In the third test case of the first sample, each segment intersects at least one of its ends with a segment of a different color, so all answers are equal to $$$0$$$.The fourth test case of the first sample is described in the problem statement.In the fifth test case of the first sample, one segment lies completely inside the other, and for both of them the answer is $$$0$$$.In the sixth test case of the first sample, all segments are points of different colors.

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.slice(l, l + n).map(str => str.trim().split(' ').map(Number))
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const ls = arr.map((x, i) => ({ x, i }))
        .sort((a, b) => a.x[0] - b.x[0])
    const left = cal(n, ls, 0)
    const rs = arr.map(([l, r, c], i) => ({ x: [-l, -r, c], i }))
        .sort((a, b) => a.x[1] - b.x[1])
    const right = cal(n, rs, 1)
    //
    const ans = Array(n)
    for (let i = 0; i < n; i++) {
        ans[i] = Math.min(left[i], right[i])
        if (ans[i] === Infinity) ans[i] = 0
    }
    // console.log(left, right)
    return ans.join(' ')
}
function cal(n, arr, key) {
    // console.log(arr)
    //
    let first = -Infinity, second = -Infinity
    let fc, sc // color
    const best = Array(n)
    for (let p = 0; p < n; p++) {
        const { x, i } = arr[p]
        const c = x[2]
        // console.log(x, first, fc, second, sc)
        //
        const other = x[key ^ 1]
        let ok = 0
        if (fc === c) {
            if (other > first) {
                first = other
            }
            ok = 1
        } else if (sc === c) {
            if (other > second) {
                second = other
            }
            ok = 1
        }
        if (ok) {
            if (first < second) {
                [first, second] = [second, first]
                ;[fc, sc] = [sc, fc]
            }
        } else {
            if (other > first) {
                second = first
                sc = fc
                first = other
                fc = c
            } else if (other > second) {
                second = other
                sc = c
            }
        }
        best[p] = [first, fc, second, sc]
    }
// console.log(best)
    const other = arr
        .slice()
        .sort((a, b) => a.x[key ^ 1] - b.x[key ^ 1])
    const ans = Array(n).fill(Infinity)
    let j = 0
    for (let p = 0; p < n; p++) {
        const { x, i } = other[p]
        const c = x[2]
        while (j + 1 < n && x[key ^ 1] >= arr[j + 1].x[key]) j++
            // console.log(x[key^1], arr[j].x[key])
        // while (j < n && x[key] > arr[j].x[key]) j++
        ;[first, fc, second, sc] = best[j]
        // console.log(x, first, fc, second, sc, '-', arr[j])
        if (fc !== c) {
            const temp = Math.max(0, x[key] - first)
            ans[i] = Math.min(ans[i], temp)
        }
        if (sc !== c) {
            const temp = Math.max(0, x[key] - second)
            ans[i] = Math.min(ans[i], temp)
        }
        // console.log(ans[i])
    }
    return ans
}

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = new Array(n);
  for (let i = 0; i < n; i++) {
    a[i] = [rn(), rn(), rn(), i];
  }
  a.sort((a, b) => {
    if (a[1] !== b[1]) return a[1] - b[1];
    return a[0] - b[0];
  });
  const res = new Array(n).fill(Infinity);
  let max = [-1, -1];
  for (let i = 0; i < n; i++) {
    const [x, y] = max;
    const j = a[i][3];
    if (x !== -1 && a[i][2] !== a[x][2]) {
      res[j] = Math.max(0, a[i][0] - a[x][1]);
    } else if (y !== -1 && a[i][2] !== a[y][2]) {
      res[j] = Math.max(0, a[i][0] - a[y][1]);
    }
    if (max[0] === -1) {
      max[0] = i;
    } else if (a[max[0]][2] === a[i][2]) {
      max[0] = i;
    } else {
      max = [i, max[0]];
    }
  }
  max = [-1, -1];
  for (let i = n - 1; i >= 0; i--) {
    const [x, y] = max;
    const j = a[i][3];
    if (x !== -1 && a[i][2] !== a[x][2]) {
      res[j] = Math.min(res[j], Math.max(0, a[x][0] - a[i][1]));
    } else if (y !== -1 && a[i][2] !== a[y][2]) {
      res[j] = Math.min(res[j], Math.max(0, a[y][0] - a[i][1]));
    }
    if (x === -1) {
      max[0] = i;
    } else if (a[i][0] < a[x][0]) {
      if (a[x][2] === a[i][2]) {
        max[0] = i;
      } else {
        max = [i, max[0]];
      }
    } else if (a[i][2] !== a[x][2] && (y === -1 || a[i][0] < a[y][0])) {
      max[1] = i;
    }
  }
  return res.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8')
.split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

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.slice(l, l + n).map(str => str.trim().split(' ').map(Number))
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const ls = arr.map((x, i) => ({ x, i }))
        .sort((a, b) => a.x[0] - b.x[0])
    const left = cal(n, ls, 0)
    const rs = arr.map(([l, r, c], i) => ({ x: [-l, -r, c], i }))
        .sort((a, b) => a.x[1] - b.x[1])
    const right = cal(n, rs, 1)
    //
    const ans = Array(n)
    for (let i = 0; i < n; i++) {
        ans[i] = Math.min(left[i], right[i])
        if (ans[i] === Infinity) ans[i] = 0
    }
    // console.log(left, right)
    return ans.join(' ')
}
function cal(n, arr, key) {
    // console.log(arr)
    const ans = Array(n).fill(Infinity)
    //
    let first = -Infinity, second = -Infinity
    let fc, sc // color
    let fi, si
    for (let p = 0; p < n; p++) {
        const { x, i } = arr[p]
        const c = x[2]
        if (fc !== c) {
            const temp = Math.max(0, x[key] - first)
            ans[i] = Math.min(ans[i], temp)
            ans[fi] = Math.min(ans[fi], temp)
        }
        if (sc !== c) {
            const temp = Math.max(0, x[key] - second)
            ans[i] = Math.min(ans[i], temp)
            ans[si] = Math.min(ans[si], temp)
        }
        // console.log(x, first, fc, second, sc)
        //
        const other = x[key ^ 1]
        let ok = 0
        if (fc === c) {
            if (other > first) {
                first = other
                fi = i
            }
            ok = 1
        } else if (sc === c) {
            if (other > second) {
                second = other
                si = i
            }
            ok = 1
        }
        if (ok) {
            if (first < second) {
                [first, second] = [second, first]
                ;[fc, sc] = [sc, fc]
                ;[fi, si] = [si, fi]
            }
        } else {
            if (other > first) {
                second = first
                sc = fc
                si = fi
                first = other
                fc = c
                fi = i
            } else if (other > second) {
                second = other
                sc = c
                si = i
            }
        }
    }
    return ans
}

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.slice(l, l + n).map(str => str.trim().split(' ').map(Number))
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})
const TreeMultiSet = (function () {
var{TreeMultiSet:t}=function(t){
/*! *****************************************************************************
        Copyright (c) Microsoft Corporation.

        Permission to use, copy, modify, and/or distribute this software for any
        purpose with or without fee is hereby granted.

        THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
        REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
        AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
        INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
        LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
        OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
        PERFORMANCE OF THIS SOFTWARE.
        ***************************************************************************** */
var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var s,u=function(){function t(t,e){this.it_=t,this.last_=e}return t.prototype.next=function(){if(this.it_.equals(this.last_))return{done:!0,value:void 0};var t=this.it_;return this.it_=this.it_.next(),{done:!1,value:t.value}},t.prototype[Symbol.iterator]=function(){return this},t}(),a=function(){function t(){}return t.prototype.empty=function(){return 0===this.size()},t.prototype.rbegin=function(){return this.end().reverse()},t.prototype.rend=function(){return this.begin().reverse()},t.prototype[Symbol.iterator]=function(){return new u(this.begin(),this.end())},t.prototype.toJSON=function(){var t,e,n=[];try{for(var o=r(this),i=o.next();!i.done;i=o.next()){var s=i.value;n.push(s)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}return n},t}(),c=function(){function t(t,e){this.data_=t,this.index_=e}return t.prototype.index=function(){return this.index_},Object.defineProperty(t.prototype,"value",{get:function(){return this.data_[this.index_]},enumerable:!1,configurable:!0}),t.prototype.prev=function(){return--this.index_,this},t.prototype.next=function(){return++this.index_,this},t.prototype.advance=function(t){return this.index_+=t,this},t.prototype.equals=function(t){return this.data_===t.data_&&this.index_===t.index_},t.prototype.swap=function(t){var e,n;e=o([t.data_,this.data_],2),this.data_=e[0],t.data_=e[1],n=o([t.index_,this.index_],2),this.index_=n[0],t.index_=n[1]},t}(),_=function(t){function e(e){var n=t.call(this)||this;return n.data_=e(n),n}return n(e,t),e.prototype.assign=function(t,e){this.clear(),this.insert(t,e)},e.prototype.clear=function(){this.data_.clear()},e.prototype.begin=function(){return this.data_.begin()},e.prototype.end=function(){return this.data_.end()},e.prototype.has=function(t){return!this.find(t).equals(this.end())},e.prototype.size=function(){return this.data_.size()},e.prototype.push=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(0===t.length)return this.size();var n=new c(t,0),r=new c(t,t.length);return this._Insert_by_range(n,r),this.size()},e.prototype.insert=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 1===t.length?this._Insert_by_key(t[0]):t[0].next instanceof Function&&t[1].next instanceof Function?this._Insert_by_range(t[0],t[1]):this._Insert_by_hint(t[0],t[1])},e.prototype.erase=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 1!==t.length||t[0]instanceof this.end().constructor&&t[0].source()===this?1===t.length?this._Erase_by_range(t[0]):this._Erase_by_range(t[0],t[1]):this._Erase_by_val(t[0])},e.prototype._Erase_by_range=function(t,e){void 0===e&&(e=t.next());var n=this.data_.erase(t,e);return this._Handle_erase(t,e),n},e}(a),l=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.insert=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t.prototype.insert.apply(this,i([],o(e),!1))},e.prototype._Erase_by_val=function(t){var e=this.find(t);if(!0===e.equals(this.end()))return 0;for(var n=e.next(),r=1;!n.equals(this.end())&&this._Key_eq(t,n.value);)n=n.next(),++r;return this._Erase_by_range(e,n),r},e.prototype.merge=function(t){this.insert(t.begin(),t.end()),t.clear()},e}(_);!function(t){t.construct=function(t){for(var e,n,r=[],s=1;s<arguments.length;s++)r[s-1]=arguments[s];return r.length>=1&&r[0]instanceof Array?(e=function(){var e=r[0];t.push.apply(t,i([],o(e),!1))},n=r.slice(1)):r.length>=2&&r[0].next instanceof Function&&r[1].next instanceof Function?(e=function(){var e=r[0],n=r[1];t.assign(e,n)},n=r.slice(2)):(e=null,n=r),{ramda:e,tail:n}}}(s||(s={}));var h=null;function p(){return null===y&&(null===h&&(h="object"==typeof global&&"object"==typeof global.process&&"object"==typeof global.process.versions&&void 0!==global.process.versions.node),void 0===(y=h?global:self).__s_iUID&&(y.__s_iUID=0)),y}var f,y=null;function v(t){if(t instanceof Object){if(!1===t.hasOwnProperty("__get_m_iUID")){var e=++p().__s_iUID;Object.defineProperty(t,"__get_m_iUID",{value:function(){return e}})}return t.__get_m_iUID()}return void 0===t?-1:0}function d(t,e){return t=t?t.valueOf():t,e=e?e.valueOf():e,t instanceof Object&&t.equals instanceof Function?t.equals(e):t===e}function g(t,e){return t=t.valueOf(),e=e.valueOf(),t instanceof Object?t.less instanceof Function?t.less(e):v(t)<v(e):t<e}function b(t,e){return e^=t?1:0,e*=k}function m(t,e){return x(t.toString(),e)}function x(t,e){for(var n=0;n<t.length;++n)e^=t.charCodeAt(n),e*=k;return Math.abs(e)}!function(t){t.construct=function(t,e,n){for(var r=[],u=3;u<arguments.length;u++)r[u-3]=arguments[u];var a=null,c=g;if(1===r.length&&r[0]instanceof e){var _=r[0];c=_.key_comp(),a=function(){var e=_.begin(),n=_.end();t.assign(e,n)}}else{var l=s.construct.apply(s,i([t],o(r),!1));a=l.ramda,l.tail.length>=1&&(c=l.tail[0])}n(c),null!==a&&a()},t.emplacable=function(t,e,n){var r=e.prev(),o=r.equals(t.end())||t.value_comp()(r.value,n);return o=o&&(e.equals(t.end())||t.value_comp()(n,e.value))}}(f||(f={}));var w,I=2166136261,k=16777619,q=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.equals=function(t){return d(this.first,t.first)&&d(this.second,t.second)},t.prototype.less=function(t){return!1===d(this.first,t.first)?g(this.first,t.first):g(this.second,t.second)},t.prototype.hashCode=function(){return function(){for(var t,e,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var i=I;try{for(var s=r(n),u=s.next();!u.done;u=s.next()){var a=u.value,c=typeof(a=a?a.valueOf():a);if("boolean"===c)i=b(a,i);else if("number"===c||"bigint"===c)i=m(a,i);else if("string"===c)i=x(a,i);else if(a instanceof Object&&a.hashCode instanceof Function){var _=a.hashCode();if(1===n.length)return _;i^=_,i*=k}else i=m(v(a),i)}}catch(e){t={error:e}}finally{try{u&&!u.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return Math.abs(i)}(this.first,this.second)},t}(),E=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.find=function(t){var e=this.lower_bound(t);return!e.equals(this.end())&&this._Key_eq(t,e.value)?e:this.end()},e.prototype.count=function(t){for(var e=this.find(t),n=0;!e.equals(this.end())&&this._Key_eq(e.value,t);e=e.next())++n;return n},e.prototype.equal_range=function(t){return new q(this.lower_bound(t),this.upper_bound(t))},e.prototype.value_comp=function(){return this.key_comp()},e.prototype._Key_eq=function(t,e){return!this.key_comp()(t,e)&&!this.key_comp()(e,t)},e.prototype._Insert_by_key=function(t){var e=this.upper_bound(t);return e=this.data_.insert(e,t),this._Handle_insert(e,e.next()),e},e.prototype._Insert_by_hint=function(t,e){if(f.emplacable(this,t,e)){var n=this.data_.insert(t,e);return this._Handle_insert(n,n.next()),n}return this._Insert_by_key(e)},e.prototype._Insert_by_range=function(t,e){for(var n=t;!n.equals(e);n=n.next())this._Insert_by_key(n.value)},e}(l),O=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e}(function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this,o=n.prototype;return Object.setPrototypeOf?Object.setPrototypeOf(r,o):r.__proto__=o,r}return n(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this.constructor.name},enumerable:!1,configurable:!0}),e.prototype.what=function(){return this.message},e.prototype.toJSON=function(){return{name:this.name,message:this.message,stack:this.stack}},e}(Error)),F=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e}(O),S=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e}(O);!function(t){function e(t){if("string"==typeof t)return t;var e=t.constructor.name;return t.constructor.__MODULE&&(e=t.constructor.__MODULE+"."+e),"std."+e}t.get_class_name=e,t.empty=function(t,n){return new S("Error on "+e(t)+"."+n+"(): it's empty container.")},t.negative_index=function(t,n,r){return new S("Error on "+e(t)+"."+n+"(): parametric index is negative -> (index = "+r+").")},t.excessive_index=function(t,n,r,o){return new S("Error on "+e(t)+"."+n+"(): parametric index is equal or greater than size -> (index = "+r+", size: "+o+").")},t.not_my_iterator=function(t,n){return new F("Error on "+e(t)+"."+n+"(): parametric iterator is not this container's own.")},t.erased_iterator=function(t,n){return new F("Error on "+e(t)+"."+n+"(): parametric iterator, it already has been erased.")},t.negative_iterator=function(t,n,r){return new S("Error on "+e(t)+"."+n+"(): parametric iterator is directing negative position -> (index = "+r+").")},t.iterator_end_value=function(t,n){void 0===n&&(n="end");var r=e(t);return new S("Error on "+r+".Iterator.value: cannot access to the "+r+"."+n+"().value.")},t.key_nout_found=function(t,n,r){throw new S("Error on "+e(t)+"."+n+"(): unable to find the matched key -> "+r)}}(w||(w={}));var j=function(){function t(t,e,n){this.prev_=t,this.next_=e,this.value_=n}return t._Set_prev=function(t,e){t.prev_=e},t._Set_next=function(t,e){t.next_=e},t.prototype.prev=function(){return this.prev_},t.prototype.next=function(){return this.next_},Object.defineProperty(t.prototype,"value",{get:function(){return this._Try_value(),this.value_},enumerable:!1,configurable:!0}),t.prototype._Try_value=function(){if(void 0===this.value_&&!0===this.equals(this.source().end()))throw w.iterator_end_value(this.source())},t.prototype.equals=function(t){return this===t},t}(),z=function(){function t(t,e){this.index_=t,this.value_=e}return t.prototype.index=function(){return this.index_},Object.defineProperty(t.prototype,"value",{get:function(){return this.value_},enumerable:!1,configurable:!0}),t.prototype.next=function(){return++this.index_,this},t.prototype.equals=function(t){return this.index_===t.index_},t}();var R=function(t){function e(){var e=t.call(this)||this;return e.end_=e._Create_iterator(null,null),e.clear(),e}return n(e,t),e.prototype.assign=function(t,e){this.clear(),this.insert(this.end(),t,e)},e.prototype.clear=function(){j._Set_prev(this.end_,this.end_),j._Set_next(this.end_,this.end_),this.begin_=this.end_,this.size_=0},e.prototype.resize=function(t){var e=t-this.size();e>0?this.insert(this.end(),e,void 0):e<0&&this.erase(function(t,e){if(0===e)return t;if(t.advance instanceof Function)return t.advance(e);var n;if(e<0){if(!(t.prev instanceof Function))throw new F("Error on std.advance(): parametric iterator is not a bi-directional iterator, thus advancing to negative direction is not possible.");n=function(t){return t.prev()},e=-e}else n=function(t){return t.next()};for(;e-- >0;)t=n(t);return t}(this.end(),-e),this.end())},e.prototype.begin=function(){return this.begin_},e.prototype.end=function(){return this.end_},e.prototype.size=function(){return this.size_},e.prototype.push_front=function(t){this.insert(this.begin_,t)},e.prototype.push_back=function(t){this.insert(this.end_,t)},e.prototype.pop_front=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,"pop_front");this.erase(this.begin_)},e.prototype.pop_back=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,"pop_back");this.erase(this.end_.prev())},e.prototype.push=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(0===t.length)return this.size();var n=new c(t,0),r=new c(t,t.length);return this._Insert_by_range(this.end(),n,r),this.size()},e.prototype.insert=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(t.source()!==this.end_.source())throw w.not_my_iterator(this.end_.source(),"insert");if(!0===t.erased_)throw w.erased_iterator(this.end_.source(),"insert");return 1===e.length?this._Insert_by_repeating_val(t,1,e[0]):2===e.length&&"number"==typeof e[0]?this._Insert_by_repeating_val(t,e[0],e[1]):this._Insert_by_range(t,e[0],e[1])},e.prototype._Insert_by_repeating_val=function(t,e,n){var r=new z(0,n),o=new z(e);return this._Insert_by_range(t,r,o)},e.prototype._Insert_by_range=function(t,e,n){for(var r=t.prev(),o=null,i=0,s=e;!1===s.equals(n);s=s.next()){var u=this._Create_iterator(r,null,s.value);0===i&&(o=u),j._Set_next(r,u),r=u,++i}return!0===t.equals(this.begin())&&(this.begin_=o),j._Set_next(r,t),j._Set_prev(t,r),this.size_+=i,o},e.prototype.erase=function(t,e){return void 0===e&&(e=t.next()),this._Erase_by_range(t,e)},e.prototype._Erase_by_range=function(t,e){if(t.source()!==this.end_.source())throw w.not_my_iterator(this.end_.source(),"insert");if(!0===t.erased_)throw w.erased_iterator(this.end_.source(),"insert");if(t.equals(this.end_))return this.end_;var n=t.prev();j._Set_next(n,e),j._Set_prev(e,n);for(var r=t;!r.equals(e);r=r.next())r.erased_=!0,--this.size_;return t.equals(this.begin_)&&(this.begin_=e),e},e.prototype.swap=function(t){var e,n,r;e=o([t.begin_,this.begin_],2),this.begin_=e[0],t.begin_=e[1],n=o([t.end_,this.end_],2),this.end_=n[0],t.end_=n[1],r=o([t.size_,this.size_],2),this.size_=r[0],t.size_=r[1]},e}(a),P=function(){function t(t){this.base_=t.prev()}return t.prototype.source=function(){return this.base_.source()},t.prototype.base=function(){return this.base_.next()},Object.defineProperty(t.prototype,"value",{get:function(){return this.base_.value},enumerable:!1,configurable:!0}),t.prototype.prev=function(){return this._Create_neighbor(this.base().next())},t.prototype.next=function(){return this._Create_neighbor(this.base_)},t.prototype.equals=function(t){return this.base_.equals(t.base_)},t}(),C=function(t){function e(e){var n=t.call(this)||this;return n.associative_=e,n}return n(e,t),e.prototype._Create_iterator=function(t,n,r){return e.Iterator.create(this,t,n,r)},e._Swap_associative=function(t,e){var n;n=o([e.associative_,t.associative_],2),t.associative_=n[0],e.associative_=n[1]},e.prototype.associative=function(){return this.associative_},e}(R);!function(t){var e=function(t){function e(e,n,r,o){var i=t.call(this,n,r,o)||this;return i.source_=e,i}return n(e,t),e.create=function(t,n,r,o){return new e(t,n,r,o)},e.prototype.reverse=function(){return new r(this)},e.prototype.source=function(){return this.source_.associative()},e}(j);t.Iterator=e;var r=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype._Create_neighbor=function(t){return new e(t)},e}(P);t.ReverseIterator=r}(C||(C={}));var M=function(){function t(t,e){this.value=t,this.color=e,this.parent=null,this.left=null,this.right=null}return Object.defineProperty(t.prototype,"grand",{get:function(){return this.parent.parent},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sibling",{get:function(){return this===this.parent.left?this.parent.right:this.parent.left},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"uncle",{get:function(){return this.parent.sibling},enumerable:!1,configurable:!0}),t}(),D=function(t){function e(e,n){return t.call(this,e,n,(function(t,e){var r=n(t.value,e.value);return r||n(e.value,t.value)?r:v(t)<v(e)}))||this}return n(e,t),e.prototype.insert=function(e){v(e),t.prototype.insert.call(this,e)},e.prototype._Nearest_by_key=function(t,e){if(null===this.root_)return null;for(var n=this.root_,r=null;;){var o=n.value,i=null;if(this.key_comp()(t,o.value)?i=n.left:this.key_comp()(o.value,t)?i=n.right:(r=n,i=e(n)),null===i)break;n=i}return null!==r?r:n},e.prototype.nearest_by_key=function(t){return this._Nearest_by_key(t,(function(t){return t.left}))},e.prototype.upper_bound=function(t){var e=this._Nearest_by_key(t,(function(t){return t.right}));if(null===e)return this.source().end();var n=e.value;return this.key_comp()(t,n.value)?n:n.next()},e}(function(t){function e(e,n,r){var o=t.call(this,r)||this;return o.source_=e,o.key_comp_=n,o.key_eq_=function(t,e){return!n(t,e)&&!n(e,t)},o}return n(e,t),e._Swap_source=function(t,e){var n;n=o([e.source_,t.source_],2),t.source_=n[0],e.source_=n[1]},e.prototype.get_by_key=function(t){var e=this.nearest_by_key(t);return null!==e&&this.key_eq_(t,e.value.value)?e:null},e.prototype.lower_bound=function(t){var e=this.nearest_by_key(t);return null===e?this.source_.end():this.key_comp_(e.value.value,t)?e.value.next():e.value},e.prototype.equal_range=function(t){return new q(this.lower_bound(t),this.upper_bound(t))},e.prototype.source=function(){return this.source_},e.prototype.key_comp=function(){return this.key_comp_},e.prototype.key_eq=function(){return this.key_eq_},e.prototype.value_comp=function(){return this.key_comp_},e}(function(){function t(t){this.root_=null,this.comp_=t,this.equal_=function(e,n){return!t(e,n)&&!t(n,e)}}return t.prototype.clear=function(){this.root_=null},t.prototype.root=function(){return this.root_},t.prototype.get=function(t){var e=this.nearest(t);return null!==e&&this.equal_(t,e.value)?e:null},t.prototype.nearest=function(t){if(null===this.root_)return null;for(var e=this.root_;;){var n=null;if(this.comp_(t,e.value))n=e.left;else{if(!this.comp_(e.value,t))return e;n=e.right}if(null===n)break;e=n}return e},t.prototype._Fetch_maximum=function(t){for(;null!==t.right;)t=t.right;return t},t.prototype.insert=function(t){var e=this.nearest(t),n=new M(t,1);null===e?this.root_=n:(n.parent=e,this.comp_(n.value,e.value)?e.left=n:e.right=n),this._Insert_case1(n)},t.prototype._Insert_case1=function(t){null===t.parent?t.color=0:this._Insert_case2(t)},t.prototype._Insert_case2=function(t){0!==this._Fetch_color(t.parent)&&this._Insert_case3(t)},t.prototype._Insert_case3=function(t){1===this._Fetch_color(t.uncle)?(t.parent.color=0,t.uncle.color=0,t.grand.color=1,this._Insert_case1(t.grand)):this._Insert_case4(t)},t.prototype._Insert_case4=function(t){t===t.parent.right&&t.parent===t.grand.left?(this._Rotate_left(t.parent),t=t.left):t===t.parent.left&&t.parent===t.grand.right&&(this._Rotate_right(t.parent),t=t.right),this._Insert_case5(t)},t.prototype._Insert_case5=function(t){t.parent.color=0,t.grand.color=1,t===t.parent.left&&t.parent===t.grand.left?this._Rotate_right(t.grand):this._Rotate_left(t.grand)},t.prototype.erase=function(t){var e=this.get(t);if(null!==e){if(null!==e.left&&null!==e.right){var n=this._Fetch_maximum(e.left);e.value=n.value,e=n}var r=null===e.right?e.left:e.right;0===this._Fetch_color(e)&&(e.color=this._Fetch_color(r),this._Erase_case1(e)),this._Replace_node(e,r),1===this._Fetch_color(this.root_)&&(this.root_.color=0)}},t.prototype._Erase_case1=function(t){null!==t.parent&&this._Erase_case2(t)},t.prototype._Erase_case2=function(t){1===this._Fetch_color(t.sibling)&&(t.parent.color=1,t.sibling.color=0,t===t.parent.left?this._Rotate_left(t.parent):this._Rotate_right(t.parent)),this._Erase_case3(t)},t.prototype._Erase_case3=function(t){0===this._Fetch_color(t.parent)&&0===this._Fetch_color(t.sibling)&&0===this._Fetch_color(t.sibling.left)&&0===this._Fetch_color(t.sibling.right)?(t.sibling.color=1,this._Erase_case1(t.parent)):this._Erase_case4(t)},t.prototype._Erase_case4=function(t){1===this._Fetch_color(t.parent)&&null!==t.sibling&&0===this._Fetch_color(t.sibling)&&0===this._Fetch_color(t.sibling.left)&&0===this._Fetch_color(t.sibling.right)?(t.sibling.color=1,t.parent.color=0):this._Erase_case5(t)},t.prototype._Erase_case5=function(t){t===t.parent.left&&null!==t.sibling&&0===this._Fetch_color(t.sibling)&&1===this._Fetch_color(t.sibling.left)&&0===this._Fetch_color(t.sibling.right)?(t.sibling.color=1,t.sibling.left.color=0,this._Rotate_right(t.sibling)):t===t.parent.right&&null!==t.sibling&&0===this._Fetch_color(t.sibling)&&0===this._Fetch_color(t.sibling.left)&&1===this._Fetch_color(t.sibling.right)&&(t.sibling.color=1,t.sibling.right.color=0,this._Rotate_left(t.sibling)),this._Erase_case6(t)},t.prototype._Erase_case6=function(t){t.sibling.color=this._Fetch_color(t.parent),t.parent.color=0,t===t.parent.left?(t.sibling.right.color=0,this._Rotate_left(t.parent)):(t.sibling.left.color=0,this._Rotate_right(t.parent))},t.prototype._Rotate_left=function(t){var e=t.right;this._Replace_node(t,e),t.right=e.left,null!==e.left&&(e.left.parent=t),e.left=t,t.parent=e},t.prototype._Rotate_right=function(t){var e=t.left;this._Replace_node(t,e),t.left=e.right,null!==e.right&&(e.right.parent=t),e.right=t,t.parent=e},t.prototype._Replace_node=function(t,e){null===t.parent?this.root_=e:t===t.parent.left?t.parent.left=e:t.parent.right=e,null!==e&&(e.parent=t.parent)},t.prototype._Fetch_color=function(t){return null===t?0:t.color},t}()));return t.TreeMultiSet=function(t){function e(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var s=t.call(this,(function(t){return new C(t)}))||this;return f.construct.apply(f,i([s,e,function(t){s.tree_=new D(s,t)}],o(n),!1)),s}return n(e,t),e.prototype.clear=function(){t.prototype.clear.call(this),this.tree_.clear()},e.prototype.swap=function(t){var e,n;e=o([t.data_,this.data_],2),this.data_=e[0],t.data_=e[1],C._Swap_associative(this.data_,t.data_),D._Swap_source(this.tree_,t.tree_),n=o([t.tree_,this.tree_],2),this.tree_=n[0],t.tree_=n[1]},e.prototype.key_comp=function(){return this.tree_.key_comp()},e.prototype.lower_bound=function(t){return this.tree_.lower_bound(t)},e.prototype.upper_bound=function(t){return this.tree_.upper_bound(t)},e.prototype._Handle_insert=function(t,e){for(;!t.equals(e);t=t.next())this.tree_.insert(t)},e.prototype._Handle_erase=function(t,e){for(;!t.equals(e);t=t.next())this.tree_.erase(t)},e}(E),function(t){t.Iterator=C.Iterator,t.ReverseIterator=C.ReverseIterator}(t.TreeMultiSet||(t.TreeMultiSet={})),Object.defineProperty(t,"__esModule",{value:!0}),t}({});

return t
})();

function solve(n, arr) {
    const gs = {}
    const ls = new TreeMultiSet((a, b) => {
        return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])
    }) // val, id
    const rs = new TreeMultiSet((a, b) => {
        return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])
    }) // val, id
    for (let i = 0; i < arr.length; i++) {
        const [l, r, c] = arr[i]
        gs[c] = gs[c] || []
        gs[c].push(i)
        ls.insert([l, i])
        rs.insert([r, i])
    }
    //
    const ans = Array(n)
    for (let c in gs) {
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            ls.erase([l, i])
            rs.erase([r, i])
        }
        //
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            let diff = Infinity, iter
            // last lx <= r || first rx >= l
            // r-1, r], r+1
            // l-1, [l, l+1
            const il = ls.upper_bound([r, Infinity])
            const ir = rs.upper_bound([l - 1, Infinity])
            // iter = ls.upper_bound([r, i]).prev()
            iter = il.prev()
            if (iter !== ls.end() && arr[iter.value[1]][1] >= l) {
                ans[i] = 0
                continue
            }
            // iter = rs.lower_bound([l, i])
            iter = ir
            if (iter !== rs.end() && arr[iter.value[1]][0] <= r) {
                ans[i] = 0
                continue
            }
            // last rx < l
            // iter = rs.lower_bound([l, i]).prev()
            iter = ir.prev()
            if (iter !== rs.end()) {
                diff = Math.min(diff, l - iter.value[0])
            }
            // first lx > r
            // iter = ls.upper_bound([r, i])
            iter = il
            if (iter !== ls.end()) {
                diff = Math.min(diff, iter.value[0] - r)
            }
            //
            ans[i] = diff
        }
        // recover
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            ls.insert([l, i])
            rs.insert([r, i])
        }
    }
    return ans.join(' ')
}

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.slice(l, l + n).map(str => str.trim().split(' ').map(Number))
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})
const TreeMultiSet = (function () {
var{TreeMultiSet:t}=function(t){
/*! *****************************************************************************
        Copyright (c) Microsoft Corporation.

        Permission to use, copy, modify, and/or distribute this software for any
        purpose with or without fee is hereby granted.

        THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
        REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
        AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
        INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
        LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
        OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
        PERFORMANCE OF THIS SOFTWARE.
        ***************************************************************************** */
var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}function r(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function o(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var s,u=function(){function t(t,e){this.it_=t,this.last_=e}return t.prototype.next=function(){if(this.it_.equals(this.last_))return{done:!0,value:void 0};var t=this.it_;return this.it_=this.it_.next(),{done:!1,value:t.value}},t.prototype[Symbol.iterator]=function(){return this},t}(),a=function(){function t(){}return t.prototype.empty=function(){return 0===this.size()},t.prototype.rbegin=function(){return this.end().reverse()},t.prototype.rend=function(){return this.begin().reverse()},t.prototype[Symbol.iterator]=function(){return new u(this.begin(),this.end())},t.prototype.toJSON=function(){var t,e,n=[];try{for(var o=r(this),i=o.next();!i.done;i=o.next()){var s=i.value;n.push(s)}}catch(e){t={error:e}}finally{try{i&&!i.done&&(e=o.return)&&e.call(o)}finally{if(t)throw t.error}}return n},t}(),c=function(){function t(t,e){this.data_=t,this.index_=e}return t.prototype.index=function(){return this.index_},Object.defineProperty(t.prototype,"value",{get:function(){return this.data_[this.index_]},enumerable:!1,configurable:!0}),t.prototype.prev=function(){return--this.index_,this},t.prototype.next=function(){return++this.index_,this},t.prototype.advance=function(t){return this.index_+=t,this},t.prototype.equals=function(t){return this.data_===t.data_&&this.index_===t.index_},t.prototype.swap=function(t){var e,n;e=o([t.data_,this.data_],2),this.data_=e[0],t.data_=e[1],n=o([t.index_,this.index_],2),this.index_=n[0],t.index_=n[1]},t}(),_=function(t){function e(e){var n=t.call(this)||this;return n.data_=e(n),n}return n(e,t),e.prototype.assign=function(t,e){this.clear(),this.insert(t,e)},e.prototype.clear=function(){this.data_.clear()},e.prototype.begin=function(){return this.data_.begin()},e.prototype.end=function(){return this.data_.end()},e.prototype.has=function(t){return!this.find(t).equals(this.end())},e.prototype.size=function(){return this.data_.size()},e.prototype.push=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(0===t.length)return this.size();var n=new c(t,0),r=new c(t,t.length);return this._Insert_by_range(n,r),this.size()},e.prototype.insert=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 1===t.length?this._Insert_by_key(t[0]):t[0].next instanceof Function&&t[1].next instanceof Function?this._Insert_by_range(t[0],t[1]):this._Insert_by_hint(t[0],t[1])},e.prototype.erase=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return 1!==t.length||t[0]instanceof this.end().constructor&&t[0].source()===this?1===t.length?this._Erase_by_range(t[0]):this._Erase_by_range(t[0],t[1]):this._Erase_by_val(t[0])},e.prototype._Erase_by_range=function(t,e){void 0===e&&(e=t.next());var n=this.data_.erase(t,e);return this._Handle_erase(t,e),n},e}(a),l=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.insert=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t.prototype.insert.apply(this,i([],o(e),!1))},e.prototype._Erase_by_val=function(t){var e=this.find(t);if(!0===e.equals(this.end()))return 0;for(var n=e.next(),r=1;!n.equals(this.end())&&this._Key_eq(t,n.value);)n=n.next(),++r;return this._Erase_by_range(e,n),r},e.prototype.merge=function(t){this.insert(t.begin(),t.end()),t.clear()},e}(_);!function(t){t.construct=function(t){for(var e,n,r=[],s=1;s<arguments.length;s++)r[s-1]=arguments[s];return r.length>=1&&r[0]instanceof Array?(e=function(){var e=r[0];t.push.apply(t,i([],o(e),!1))},n=r.slice(1)):r.length>=2&&r[0].next instanceof Function&&r[1].next instanceof Function?(e=function(){var e=r[0],n=r[1];t.assign(e,n)},n=r.slice(2)):(e=null,n=r),{ramda:e,tail:n}}}(s||(s={}));var h=null;function p(){return null===y&&(null===h&&(h="object"==typeof global&&"object"==typeof global.process&&"object"==typeof global.process.versions&&void 0!==global.process.versions.node),void 0===(y=h?global:self).__s_iUID&&(y.__s_iUID=0)),y}var f,y=null;function v(t){if(t instanceof Object){if(!1===t.hasOwnProperty("__get_m_iUID")){var e=++p().__s_iUID;Object.defineProperty(t,"__get_m_iUID",{value:function(){return e}})}return t.__get_m_iUID()}return void 0===t?-1:0}function d(t,e){return t=t?t.valueOf():t,e=e?e.valueOf():e,t instanceof Object&&t.equals instanceof Function?t.equals(e):t===e}function g(t,e){return t=t.valueOf(),e=e.valueOf(),t instanceof Object?t.less instanceof Function?t.less(e):v(t)<v(e):t<e}function b(t,e){return e^=t?1:0,e*=k}function m(t,e){return x(t.toString(),e)}function x(t,e){for(var n=0;n<t.length;++n)e^=t.charCodeAt(n),e*=k;return Math.abs(e)}!function(t){t.construct=function(t,e,n){for(var r=[],u=3;u<arguments.length;u++)r[u-3]=arguments[u];var a=null,c=g;if(1===r.length&&r[0]instanceof e){var _=r[0];c=_.key_comp(),a=function(){var e=_.begin(),n=_.end();t.assign(e,n)}}else{var l=s.construct.apply(s,i([t],o(r),!1));a=l.ramda,l.tail.length>=1&&(c=l.tail[0])}n(c),null!==a&&a()},t.emplacable=function(t,e,n){var r=e.prev(),o=r.equals(t.end())||t.value_comp()(r.value,n);return o=o&&(e.equals(t.end())||t.value_comp()(n,e.value))}}(f||(f={}));var w,I=2166136261,k=16777619,q=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.equals=function(t){return d(this.first,t.first)&&d(this.second,t.second)},t.prototype.less=function(t){return!1===d(this.first,t.first)?g(this.first,t.first):g(this.second,t.second)},t.prototype.hashCode=function(){return function(){for(var t,e,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var i=I;try{for(var s=r(n),u=s.next();!u.done;u=s.next()){var a=u.value,c=typeof(a=a?a.valueOf():a);if("boolean"===c)i=b(a,i);else if("number"===c||"bigint"===c)i=m(a,i);else if("string"===c)i=x(a,i);else if(a instanceof Object&&a.hashCode instanceof Function){var _=a.hashCode();if(1===n.length)return _;i^=_,i*=k}else i=m(v(a),i)}}catch(e){t={error:e}}finally{try{u&&!u.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}return Math.abs(i)}(this.first,this.second)},t}(),E=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.find=function(t){var e=this.lower_bound(t);return!e.equals(this.end())&&this._Key_eq(t,e.value)?e:this.end()},e.prototype.count=function(t){for(var e=this.find(t),n=0;!e.equals(this.end())&&this._Key_eq(e.value,t);e=e.next())++n;return n},e.prototype.equal_range=function(t){return new q(this.lower_bound(t),this.upper_bound(t))},e.prototype.value_comp=function(){return this.key_comp()},e.prototype._Key_eq=function(t,e){return!this.key_comp()(t,e)&&!this.key_comp()(e,t)},e.prototype._Insert_by_key=function(t){var e=this.upper_bound(t);return e=this.data_.insert(e,t),this._Handle_insert(e,e.next()),e},e.prototype._Insert_by_hint=function(t,e){if(f.emplacable(this,t,e)){var n=this.data_.insert(t,e);return this._Handle_insert(n,n.next()),n}return this._Insert_by_key(e)},e.prototype._Insert_by_range=function(t,e){for(var n=t;!n.equals(e);n=n.next())this._Insert_by_key(n.value)},e}(l),O=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e}(function(t){function e(e){var n=this.constructor,r=t.call(this,e)||this,o=n.prototype;return Object.setPrototypeOf?Object.setPrototypeOf(r,o):r.__proto__=o,r}return n(e,t),Object.defineProperty(e.prototype,"name",{get:function(){return this.constructor.name},enumerable:!1,configurable:!0}),e.prototype.what=function(){return this.message},e.prototype.toJSON=function(){return{name:this.name,message:this.message,stack:this.stack}},e}(Error)),F=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e}(O),S=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e}(O);!function(t){function e(t){if("string"==typeof t)return t;var e=t.constructor.name;return t.constructor.__MODULE&&(e=t.constructor.__MODULE+"."+e),"std."+e}t.get_class_name=e,t.empty=function(t,n){return new S("Error on "+e(t)+"."+n+"(): it's empty container.")},t.negative_index=function(t,n,r){return new S("Error on "+e(t)+"."+n+"(): parametric index is negative -> (index = "+r+").")},t.excessive_index=function(t,n,r,o){return new S("Error on "+e(t)+"."+n+"(): parametric index is equal or greater than size -> (index = "+r+", size: "+o+").")},t.not_my_iterator=function(t,n){return new F("Error on "+e(t)+"."+n+"(): parametric iterator is not this container's own.")},t.erased_iterator=function(t,n){return new F("Error on "+e(t)+"."+n+"(): parametric iterator, it already has been erased.")},t.negative_iterator=function(t,n,r){return new S("Error on "+e(t)+"."+n+"(): parametric iterator is directing negative position -> (index = "+r+").")},t.iterator_end_value=function(t,n){void 0===n&&(n="end");var r=e(t);return new S("Error on "+r+".Iterator.value: cannot access to the "+r+"."+n+"().value.")},t.key_nout_found=function(t,n,r){throw new S("Error on "+e(t)+"."+n+"(): unable to find the matched key -> "+r)}}(w||(w={}));var j=function(){function t(t,e,n){this.prev_=t,this.next_=e,this.value_=n}return t._Set_prev=function(t,e){t.prev_=e},t._Set_next=function(t,e){t.next_=e},t.prototype.prev=function(){return this.prev_},t.prototype.next=function(){return this.next_},Object.defineProperty(t.prototype,"value",{get:function(){return this._Try_value(),this.value_},enumerable:!1,configurable:!0}),t.prototype._Try_value=function(){if(void 0===this.value_&&!0===this.equals(this.source().end()))throw w.iterator_end_value(this.source())},t.prototype.equals=function(t){return this===t},t}(),z=function(){function t(t,e){this.index_=t,this.value_=e}return t.prototype.index=function(){return this.index_},Object.defineProperty(t.prototype,"value",{get:function(){return this.value_},enumerable:!1,configurable:!0}),t.prototype.next=function(){return++this.index_,this},t.prototype.equals=function(t){return this.index_===t.index_},t}();var R=function(t){function e(){var e=t.call(this)||this;return e.end_=e._Create_iterator(null,null),e.clear(),e}return n(e,t),e.prototype.assign=function(t,e){this.clear(),this.insert(this.end(),t,e)},e.prototype.clear=function(){j._Set_prev(this.end_,this.end_),j._Set_next(this.end_,this.end_),this.begin_=this.end_,this.size_=0},e.prototype.resize=function(t){var e=t-this.size();e>0?this.insert(this.end(),e,void 0):e<0&&this.erase(function(t,e){if(0===e)return t;if(t.advance instanceof Function)return t.advance(e);var n;if(e<0){if(!(t.prev instanceof Function))throw new F("Error on std.advance(): parametric iterator is not a bi-directional iterator, thus advancing to negative direction is not possible.");n=function(t){return t.prev()},e=-e}else n=function(t){return t.next()};for(;e-- >0;)t=n(t);return t}(this.end(),-e),this.end())},e.prototype.begin=function(){return this.begin_},e.prototype.end=function(){return this.end_},e.prototype.size=function(){return this.size_},e.prototype.push_front=function(t){this.insert(this.begin_,t)},e.prototype.push_back=function(t){this.insert(this.end_,t)},e.prototype.pop_front=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,"pop_front");this.erase(this.begin_)},e.prototype.pop_back=function(){if(!0===this.empty())throw w.empty(this.end_.source().constructor.name,"pop_back");this.erase(this.end_.prev())},e.prototype.push=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(0===t.length)return this.size();var n=new c(t,0),r=new c(t,t.length);return this._Insert_by_range(this.end(),n,r),this.size()},e.prototype.insert=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(t.source()!==this.end_.source())throw w.not_my_iterator(this.end_.source(),"insert");if(!0===t.erased_)throw w.erased_iterator(this.end_.source(),"insert");return 1===e.length?this._Insert_by_repeating_val(t,1,e[0]):2===e.length&&"number"==typeof e[0]?this._Insert_by_repeating_val(t,e[0],e[1]):this._Insert_by_range(t,e[0],e[1])},e.prototype._Insert_by_repeating_val=function(t,e,n){var r=new z(0,n),o=new z(e);return this._Insert_by_range(t,r,o)},e.prototype._Insert_by_range=function(t,e,n){for(var r=t.prev(),o=null,i=0,s=e;!1===s.equals(n);s=s.next()){var u=this._Create_iterator(r,null,s.value);0===i&&(o=u),j._Set_next(r,u),r=u,++i}return!0===t.equals(this.begin())&&(this.begin_=o),j._Set_next(r,t),j._Set_prev(t,r),this.size_+=i,o},e.prototype.erase=function(t,e){return void 0===e&&(e=t.next()),this._Erase_by_range(t,e)},e.prototype._Erase_by_range=function(t,e){if(t.source()!==this.end_.source())throw w.not_my_iterator(this.end_.source(),"insert");if(!0===t.erased_)throw w.erased_iterator(this.end_.source(),"insert");if(t.equals(this.end_))return this.end_;var n=t.prev();j._Set_next(n,e),j._Set_prev(e,n);for(var r=t;!r.equals(e);r=r.next())r.erased_=!0,--this.size_;return t.equals(this.begin_)&&(this.begin_=e),e},e.prototype.swap=function(t){var e,n,r;e=o([t.begin_,this.begin_],2),this.begin_=e[0],t.begin_=e[1],n=o([t.end_,this.end_],2),this.end_=n[0],t.end_=n[1],r=o([t.size_,this.size_],2),this.size_=r[0],t.size_=r[1]},e}(a),P=function(){function t(t){this.base_=t.prev()}return t.prototype.source=function(){return this.base_.source()},t.prototype.base=function(){return this.base_.next()},Object.defineProperty(t.prototype,"value",{get:function(){return this.base_.value},enumerable:!1,configurable:!0}),t.prototype.prev=function(){return this._Create_neighbor(this.base().next())},t.prototype.next=function(){return this._Create_neighbor(this.base_)},t.prototype.equals=function(t){return this.base_.equals(t.base_)},t}(),C=function(t){function e(e){var n=t.call(this)||this;return n.associative_=e,n}return n(e,t),e.prototype._Create_iterator=function(t,n,r){return e.Iterator.create(this,t,n,r)},e._Swap_associative=function(t,e){var n;n=o([e.associative_,t.associative_],2),t.associative_=n[0],e.associative_=n[1]},e.prototype.associative=function(){return this.associative_},e}(R);!function(t){var e=function(t){function e(e,n,r,o){var i=t.call(this,n,r,o)||this;return i.source_=e,i}return n(e,t),e.create=function(t,n,r,o){return new e(t,n,r,o)},e.prototype.reverse=function(){return new r(this)},e.prototype.source=function(){return this.source_.associative()},e}(j);t.Iterator=e;var r=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype._Create_neighbor=function(t){return new e(t)},e}(P);t.ReverseIterator=r}(C||(C={}));var M=function(){function t(t,e){this.value=t,this.color=e,this.parent=null,this.left=null,this.right=null}return Object.defineProperty(t.prototype,"grand",{get:function(){return this.parent.parent},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"sibling",{get:function(){return this===this.parent.left?this.parent.right:this.parent.left},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"uncle",{get:function(){return this.parent.sibling},enumerable:!1,configurable:!0}),t}(),D=function(t){function e(e,n){return t.call(this,e,n,(function(t,e){var r=n(t.value,e.value);return r||n(e.value,t.value)?r:v(t)<v(e)}))||this}return n(e,t),e.prototype.insert=function(e){v(e),t.prototype.insert.call(this,e)},e.prototype._Nearest_by_key=function(t,e){if(null===this.root_)return null;for(var n=this.root_,r=null;;){var o=n.value,i=null;if(this.key_comp()(t,o.value)?i=n.left:this.key_comp()(o.value,t)?i=n.right:(r=n,i=e(n)),null===i)break;n=i}return null!==r?r:n},e.prototype.nearest_by_key=function(t){return this._Nearest_by_key(t,(function(t){return t.left}))},e.prototype.upper_bound=function(t){var e=this._Nearest_by_key(t,(function(t){return t.right}));if(null===e)return this.source().end();var n=e.value;return this.key_comp()(t,n.value)?n:n.next()},e}(function(t){function e(e,n,r){var o=t.call(this,r)||this;return o.source_=e,o.key_comp_=n,o.key_eq_=function(t,e){return!n(t,e)&&!n(e,t)},o}return n(e,t),e._Swap_source=function(t,e){var n;n=o([e.source_,t.source_],2),t.source_=n[0],e.source_=n[1]},e.prototype.get_by_key=function(t){var e=this.nearest_by_key(t);return null!==e&&this.key_eq_(t,e.value.value)?e:null},e.prototype.lower_bound=function(t){var e=this.nearest_by_key(t);return null===e?this.source_.end():this.key_comp_(e.value.value,t)?e.value.next():e.value},e.prototype.equal_range=function(t){return new q(this.lower_bound(t),this.upper_bound(t))},e.prototype.source=function(){return this.source_},e.prototype.key_comp=function(){return this.key_comp_},e.prototype.key_eq=function(){return this.key_eq_},e.prototype.value_comp=function(){return this.key_comp_},e}(function(){function t(t){this.root_=null,this.comp_=t,this.equal_=function(e,n){return!t(e,n)&&!t(n,e)}}return t.prototype.clear=function(){this.root_=null},t.prototype.root=function(){return this.root_},t.prototype.get=function(t){var e=this.nearest(t);return null!==e&&this.equal_(t,e.value)?e:null},t.prototype.nearest=function(t){if(null===this.root_)return null;for(var e=this.root_;;){var n=null;if(this.comp_(t,e.value))n=e.left;else{if(!this.comp_(e.value,t))return e;n=e.right}if(null===n)break;e=n}return e},t.prototype._Fetch_maximum=function(t){for(;null!==t.right;)t=t.right;return t},t.prototype.insert=function(t){var e=this.nearest(t),n=new M(t,1);null===e?this.root_=n:(n.parent=e,this.comp_(n.value,e.value)?e.left=n:e.right=n),this._Insert_case1(n)},t.prototype._Insert_case1=function(t){null===t.parent?t.color=0:this._Insert_case2(t)},t.prototype._Insert_case2=function(t){0!==this._Fetch_color(t.parent)&&this._Insert_case3(t)},t.prototype._Insert_case3=function(t){1===this._Fetch_color(t.uncle)?(t.parent.color=0,t.uncle.color=0,t.grand.color=1,this._Insert_case1(t.grand)):this._Insert_case4(t)},t.prototype._Insert_case4=function(t){t===t.parent.right&&t.parent===t.grand.left?(this._Rotate_left(t.parent),t=t.left):t===t.parent.left&&t.parent===t.grand.right&&(this._Rotate_right(t.parent),t=t.right),this._Insert_case5(t)},t.prototype._Insert_case5=function(t){t.parent.color=0,t.grand.color=1,t===t.parent.left&&t.parent===t.grand.left?this._Rotate_right(t.grand):this._Rotate_left(t.grand)},t.prototype.erase=function(t){var e=this.get(t);if(null!==e){if(null!==e.left&&null!==e.right){var n=this._Fetch_maximum(e.left);e.value=n.value,e=n}var r=null===e.right?e.left:e.right;0===this._Fetch_color(e)&&(e.color=this._Fetch_color(r),this._Erase_case1(e)),this._Replace_node(e,r),1===this._Fetch_color(this.root_)&&(this.root_.color=0)}},t.prototype._Erase_case1=function(t){null!==t.parent&&this._Erase_case2(t)},t.prototype._Erase_case2=function(t){1===this._Fetch_color(t.sibling)&&(t.parent.color=1,t.sibling.color=0,t===t.parent.left?this._Rotate_left(t.parent):this._Rotate_right(t.parent)),this._Erase_case3(t)},t.prototype._Erase_case3=function(t){0===this._Fetch_color(t.parent)&&0===this._Fetch_color(t.sibling)&&0===this._Fetch_color(t.sibling.left)&&0===this._Fetch_color(t.sibling.right)?(t.sibling.color=1,this._Erase_case1(t.parent)):this._Erase_case4(t)},t.prototype._Erase_case4=function(t){1===this._Fetch_color(t.parent)&&null!==t.sibling&&0===this._Fetch_color(t.sibling)&&0===this._Fetch_color(t.sibling.left)&&0===this._Fetch_color(t.sibling.right)?(t.sibling.color=1,t.parent.color=0):this._Erase_case5(t)},t.prototype._Erase_case5=function(t){t===t.parent.left&&null!==t.sibling&&0===this._Fetch_color(t.sibling)&&1===this._Fetch_color(t.sibling.left)&&0===this._Fetch_color(t.sibling.right)?(t.sibling.color=1,t.sibling.left.color=0,this._Rotate_right(t.sibling)):t===t.parent.right&&null!==t.sibling&&0===this._Fetch_color(t.sibling)&&0===this._Fetch_color(t.sibling.left)&&1===this._Fetch_color(t.sibling.right)&&(t.sibling.color=1,t.sibling.right.color=0,this._Rotate_left(t.sibling)),this._Erase_case6(t)},t.prototype._Erase_case6=function(t){t.sibling.color=this._Fetch_color(t.parent),t.parent.color=0,t===t.parent.left?(t.sibling.right.color=0,this._Rotate_left(t.parent)):(t.sibling.left.color=0,this._Rotate_right(t.parent))},t.prototype._Rotate_left=function(t){var e=t.right;this._Replace_node(t,e),t.right=e.left,null!==e.left&&(e.left.parent=t),e.left=t,t.parent=e},t.prototype._Rotate_right=function(t){var e=t.left;this._Replace_node(t,e),t.left=e.right,null!==e.right&&(e.right.parent=t),e.right=t,t.parent=e},t.prototype._Replace_node=function(t,e){null===t.parent?this.root_=e:t===t.parent.left?t.parent.left=e:t.parent.right=e,null!==e&&(e.parent=t.parent)},t.prototype._Fetch_color=function(t){return null===t?0:t.color},t}()));return t.TreeMultiSet=function(t){function e(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var s=t.call(this,(function(t){return new C(t)}))||this;return f.construct.apply(f,i([s,e,function(t){s.tree_=new D(s,t)}],o(n),!1)),s}return n(e,t),e.prototype.clear=function(){t.prototype.clear.call(this),this.tree_.clear()},e.prototype.swap=function(t){var e,n;e=o([t.data_,this.data_],2),this.data_=e[0],t.data_=e[1],C._Swap_associative(this.data_,t.data_),D._Swap_source(this.tree_,t.tree_),n=o([t.tree_,this.tree_],2),this.tree_=n[0],t.tree_=n[1]},e.prototype.key_comp=function(){return this.tree_.key_comp()},e.prototype.lower_bound=function(t){return this.tree_.lower_bound(t)},e.prototype.upper_bound=function(t){return this.tree_.upper_bound(t)},e.prototype._Handle_insert=function(t,e){for(;!t.equals(e);t=t.next())this.tree_.insert(t)},e.prototype._Handle_erase=function(t,e){for(;!t.equals(e);t=t.next())this.tree_.erase(t)},e}(E),function(t){t.Iterator=C.Iterator,t.ReverseIterator=C.ReverseIterator}(t.TreeMultiSet||(t.TreeMultiSet={})),Object.defineProperty(t,"__esModule",{value:!0}),t}({});

return t
})();

function solve(n, arr) {
    const gs = {}
    const ls = new TreeMultiSet((a, b) => {
        return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])
    }) // val, id
    const rs = new TreeMultiSet((a, b) => {
        return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])
    }) // val, id
    for (let i = 0; i < arr.length; i++) {
        const [l, r, c] = arr[i]
        gs[c] = gs[c] || []
        gs[c].push(i)
        ls.insert([l, i])
        rs.insert([r, i])
    }
    //
    const ans = Array(n)
    for (let c in gs) {
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            ls.erase([l, i])
            rs.erase([r, i])
        }
        //
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            let diff = Infinity, iter
            // last lx <= r || first rx >= l
            iter = ls.upper_bound([r, i]).prev()
            if (iter !== ls.end() && arr[iter.value[1]][1] >= l) {
                ans[i] = 0
                continue
            }
            iter = rs.lower_bound([l, i])
            if (iter !== rs.end() && arr[iter.value[1]][0] <= r) {
                ans[i] = 0
                continue
            }
            // last rx < l
            iter = rs.lower_bound([l, i]).prev()
            if (iter !== rs.end()) {
                diff = Math.min(diff, l - iter.value[0])
            }
            // first lx > r
            iter = ls.upper_bound([r, i])
            if (iter !== ls.end()) {
                diff = Math.min(diff, iter.value[0] - r)
            }
            //
            ans[i] = diff
        }
        // recover
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            ls.insert([l, i])
            rs.insert([r, i])
        }
    }
    return ans.join(' ')
}

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.slice(l, l + n).map(str => str.trim().split(' ').map(Number))
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const xs = {}
    for (let i = 0; i < arr.length; i++) {
        const [l, r, c] = arr[i]
        xs[l] = 1
        xs[r] = 1
    }
    const sorted = Object.keys(xs)
        .map(Number)
        .sort((a, b) => a - b)
    const rm = sorted.reduce((o, x, i) => {
        o[x] = i
        return o
        }, {})
    arr = arr.map(([l, r, c]) => [rm[l], rm[r], c])
    //
    const N = sorted.length
    const gs = {}
    const tree = []
    createTree(tree, 0, 0, N - 1, 0)
    for (let i = 0; i < arr.length; i++) {
        const [l, r, c] = arr[i]
        gs[c] = gs[c] || []
        gs[c].push(i)
        insertTree(tree, 0, l, r, 1)
    }
    //
    const ans = Array(n)
    for (let c in gs) {
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            insertTree(tree, 0, l, r, -1)
        }
        //
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            const diff = binarySearch(0, 1e9, d => {
                const ll = l - binarySearch(0, l, p => {
                    return sorted[l] - sorted[l - p] <= d
                })
                const rr = binarySearch(r, sorted.length - 1, p => {
                    return sorted[p] - sorted[r] <= d
                })
                return queryTree(tree, 0, ll, rr) <= 0
            }) + 1
            ans[i] = diff
        }
        // recover
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            insertTree(tree, 0, l, r, 1)
        }
    }
    return ans.join(' ')
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}
function createTree(tree, p, left, right, val) {
    tree[p] = { left, right, val, lazy: val }
    if (left === right) return

    const mid = Math.floor((left + right) / 2)
    createTree(tree, 2 * p + 1, left, mid, val)
    createTree(tree, 2 * p + 2, mid + 1, right, val)
}
function initTree(tree, merge, arr) {
    for (let i = tree.length - 1; i >= 0; i--) {
        if (!tree[i]) continue
        const { left, right } = tree[i]
        tree[i].val = left === right
            ? arr[left % arr.length]
            : merge(tree[2 * i + 1].val, tree[2 * i + 2].val)
    }
}
function insertTree(tree, idx, l, r, val) { // same l, r
    const { left, right, lazy } = tree[idx]
    if (l <= left && r >= right) {
        tree[idx].val += val * (right - left + 1)
        tree[idx].lazy += val
        return
    }

    if (lazy && left !== right) {
        tree[2 * idx + 1].val += lazy
        tree[2 * idx + 2].val += lazy
        tree[2 * idx + 1].lazy += lazy
        tree[2 * idx + 2].lazy += lazy
        tree[idx].lazy = 0
    }

    const mid = Math.floor((left + right) / 2)
    if (l <= mid) {
        insertTree(tree, 2 * idx + 1, l, r, val)
    }
    if (r > mid) {
        insertTree(tree, 2 * idx + 2, l, r, val)
    }
    const merge = add
    tree[idx].val = merge(tree[2 * idx + 1].val, tree[2 * idx + 2].val)
}
function queryTree(tree, idx, l, r) {
    const { left, right, val, lazy } = tree[idx]
    if (l <= left && r >= right) return val

    const mid = Math.floor((left + right) / 2)
    if (lazy) {
        tree[2 * idx + 1].val += lazy
        tree[2 * idx + 2].val += lazy
        tree[2 * idx + 1].lazy += lazy
        tree[2 * idx + 2].lazy += lazy
        tree[idx].lazy = 0
    }

    let a = 0
    let b = 0
    if (l <= mid) {
        a = queryTree(tree, 2 * idx + 1, l, r)
    }
    if (r > mid) {
        b = queryTree(tree, 2 * idx + 2, l, r)
    }
    const merge = add
    return merge(a, b)
}
function add(a, b) {
    return a + b
}

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.slice(l, l + n).map(str => str.trim().split(' ').map(Number))
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})
function ceilPow2(n) {
    let x = 0
    while ((1 << x) < n) x++
    return x
}

class LazySegTree {
    constructor(nOrArray, options) {
        const { op, e, mapping, composition, id } = options
        this.op = op
        this.e = e
        const v = Array.isArray(nOrArray) ? nOrArray : Array(nOrArray).fill(0).map(() => e())

        const n = v.length
        const log = ceilPow2(n)
        const size = 1 << log
        const d = Array(2 * size)
        const lz = Array(size)
        this.n = n
        this.log = log
        this.size = size
        this.d = d
        this.lz = lz
        this.mapping = mapping
        this.composition = composition
        this.id = id

        for (let i = 0; i < d.length; i++) {
            d[i] = e()
        }
        for (let i = 0; i < lz.length; i++) {
            lz[i] = id()
        }
        for (let i = 0; i < n; i++) {
            d[size + i] = v[i]
        }
        for (let i = size - 1; i >= 1; i--) {
            this.update(i)
        }
    }
    set(p, x) {
        p += this.size
        for (let i = this.log; i >= 1; i--) this.push(p >> i);
        this.d[p] = x
        for (let i = 1; i <= this.log; i++) this.update(p >> i)
    }
    get(p) {
        const { size, log } = this
        p += size
        for (let i = log; i >= 1; i--) this.push(p >> i)
        return this.d[p]
    }
    prod(l, r) {
        const { log, size, d, op, e } = this
        if (l === r) return e()

        let sml = e(), smr = e()
        l += size
        r += size

        for (let i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) this.push(l >> i)
            if (((r >> i) << i) != r) this.push((r - 1) >> i)
        }

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++])
            if (r & 1) smr = op(d[--r], smr)
            l >>= 1
            r >>= 1
        }
        return op(sml, smr)
    }
    allProd() {
        return this.d[1]
    }
    apply(p, f) {
        const { size, log, d, mapping } = this
        p += size
        for (let i = log; i >= 1; i--) this.push(p >> i)
        d[p] = mapping(f, d[p])
        for (let i = 1; i <= log; i++) this.update(p >> i)
    }
    applyRange(l, r, f) {
        if (l == r) return

        const { size, log } = this
        l += size
        r += size

        for (let i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) this.push(l >> i)
            if (((r >> i) << i) != r) this.push((r - 1) >> i)
        }

        {
            let l2 = l, r2 = r
            while (l < r) {
                if (l & 1) this.allApply(l++, f)
                if (r & 1) this.allApply(--r, f)
                l >>= 1
                r >>= 1
            }
            l = l2
            r = r2
        }

        for (let i = 1; i <= log; i++) {
            if (((l >> i) << i) != l) this.update(l >> i)
            if (((r >> i) << i) != r) this.update((r - 1) >> i)
        }
    }
    maxRight(l, f) {
        const { n, size, log, d, op, e} = this
        if (l == n) return n
        l += size
        for (let i = log; i >= 1; i--) this.push(l >> i)
        let sm = e()
        do {
            while (l % 2 == 0) l >>= 1
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    this.push(l)
                    l = (2 * l)
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l])
                        l++
                    }
                }
                return l - size
            }
            sm = op(sm, d[l])
            l++
        } while ((l & -l) != l)
        return n
    }
    minLeft(r, f) {
        if (r == 0) return 0
        const { size, log, d, op, e} = this
        r += size
        for (let i = log; i >= 1; i--) this.push((r - 1) >> i)
        let sm = e()
        do {
            r--
            while (r > 1 && (r % 2)) r >>= 1
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    this.push(r)
                    r = (2 * r + 1)
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm)
                        r--
                    }
                }
                return r + 1 - size
            }
            sm = op(d[r], sm)
        } while ((r & -r) != r)
        return 0
    }

    update(k) {
        const { d, op } = this
        d[k] = op(d[2 * k], d[2 * k + 1])
    }
    allApply(k, f) {
        const { size, d, lz, mapping, composition } = this
        d[k] = mapping(f, d[k])
        if (k < size) lz[k] = composition(f, lz[k])
    }
    push(k) {
        const { lz, id } = this
        this.allApply(2 * k, lz[k])
        this.allApply(2 * k + 1, lz[k])
        lz[k] = id()
    }
}

// for sum
const segOptions = {
    op: (a, b) => [a[0] + b[0], a[1] + b[1]],
    e: () => [0, 0], // val, len
    mapping: (a, b) => [a * b[1] + b[0], b[1]],
    composition: (a, b) => a + b,
    id: () => 0,
}

function solve(n, arr) {
    const xs = {}
    for (let i = 0; i < arr.length; i++) {
        const [l, r, c] = arr[i]
        xs[l] = 1
        xs[r] = 1
    }
    const sorted = Object.keys(xs)
        .map(Number)
        .sort((a, b) => a - b)
    const rm = sorted.reduce((o, x, i) => {
        o[x] = i
        return o
        }, {})
    arr = arr.map(([l, r, c]) => [rm[l], rm[r], c])
    // console.log(rm)
    //
    const N = sorted.length
    const gs = {}
    const seg = new LazySegTree(N, segOptions)
    for (let i = 0; i < N; i++) {
        seg.set(i, [0, 1])
    }
    for (let i = 0; i < arr.length; i++) {
        const [l, r, c] = arr[i]
        // }
        // for (let [l, r, c] of arr) {
        gs[c] = gs[c] || []
        gs[c].push(i)
        seg.applyRange(l, r + 1, 1)
        // console.log(l, r, seg.allProd())
        // console.log(seg.d)
    }
    // console.log(gs)
        // console.log(seg.allProd())
    const ans = Array(n)
    for (let c in gs) {
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            seg.applyRange(l, r + 1, -1)
        }
        //
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            const s = seg.prod(l, r + 1)[0]
            if (s) {
                ans[i] = 0
            } else {
                const diff = binarySearch(1, N - 1, d => {
                    return seg.prod(Math.max(0, l - d), Math.min(N - 1, r + d) + 1)[0] <= 0
                }) + 1
                // const ll = Math.max(0, l - diff)
                // const rr = Math.min(N - 1, r + diff)
                // const q = queryTree(tree, 0, ll, rr)
                // console.log(ll, rr, q)
                const left = l - diff >= 0 ? sorted[l] - sorted[l - diff] : Infinity
                const right = r + diff < N ? sorted[r + diff] - sorted[r] : Infinity
                ans[i] = Math.min(left, right)
                // console.log(i, l, r, diff)
            }
        }
        // recover
        for (let i of gs[c]) {
            const [l, r] = arr[i]
            seg.applyRange(l, r + 1, 1)
        }
    }
    return ans.join(' ')
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}


The game of Berland poker is played with a deck of $$$n$$$ cards, $$$m$$$ of which are jokers. $$$k$$$ players play this game ($$$n$$$ is divisible by $$$k$$$).At the beginning of the game, each player takes $$$\frac{n}{k}$$$ cards from the deck (so each card is taken by exactly one player). The player who has the maximum number of jokers is the winner, and he gets the number of points equal to $$$x - y$$$, where $$$x$$$ is the number of jokers in the winner's hand, and $$$y$$$ is the maximum number of jokers among all other players. If there are two or more players with maximum number of jokers, all of them are winners and they get $$$0$$$ points.Here are some examples:  $$$n = 8$$$, $$$m = 3$$$, $$$k = 2$$$. If one player gets $$$3$$$ jokers and $$$1$$$ plain card, and another player gets $$$0$$$ jokers and $$$4$$$ plain cards, then the first player is the winner and gets $$$3 - 0 = 3$$$ points;  $$$n = 4$$$, $$$m = 2$$$, $$$k = 4$$$. Two players get plain cards, and the other two players get jokers, so both of them are winners and get $$$0$$$ points;  $$$n = 9$$$, $$$m = 6$$$, $$$k = 3$$$. If the first player gets $$$3$$$ jokers, the second player gets $$$1$$$ joker and $$$2$$$ plain cards, and the third player gets $$$2$$$ jokers and $$$1$$$ plain card, then the first player is the winner, and he gets $$$3 - 2 = 1$$$ point;  $$$n = 42$$$, $$$m = 0$$$, $$$k = 7$$$. Since there are no jokers, everyone gets $$$0$$$ jokers, everyone is a winner, and everyone gets $$$0$$$ points. Given $$$n$$$, $$$m$$$ and $$$k$$$, calculate the maximum number of points a player can get for winning the game.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. Then the test cases follow. Each test case contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 50$$$, $$$0 \le m \le n$$$, $$$2 \le k \le n$$$, $$$k$$$ is a divisors of $$$n$$$).

For each test case, print one integer — the maximum number of points a player can get for winning the game.

NoteTest cases of the example are described in the statement.

//↓見なくていいよ！ここから--------------------------------------------------
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);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
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){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var n = one[0];
		var m = one[1];
		var k = one[2];
		var single = n / k;
		if(single >= m){
			output[i] = m;
		}else{
			var amari = m - single;
			var hoka = Math.ceil(amari / (k - 1));
			output[i] = single - hoka;
		}
	}
	myout(myconv(output,9));
}

'use strict';

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

let inputString = [];
let currentLine = 0;

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

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

    //withTiming(main);
    main();
});

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

const withTiming = callback => {
    const start = new Date();
    callback();
    console.log(`Took ${new Date() - start} ms`);
}

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

    for (let i = 0; i < t; i++) {
        const [cards, jokers, players] = readline().split(' ').map(x => parseInt(x));

        const cardsPerPlayer = parseInt(cards / players);
        const jokersWinner = Math.min(cardsPerPlayer, jokers);
        const spreadJokers = Math.ceil((jokers - jokersWinner) / (players - 1));
        const result = jokersWinner - spreadJokers;

        console.log(Math.max(0, result));
    }
}

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const [n, m, k] = lines[i+1].split(' ').map(x => +x)
    const max = Math.min(m, n/k)
    const rest = m - max
    const min = Math.ceil(rest / (k-1))
    console.log(max - min)
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

'use strict';
// node.js
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    var testCases = parseInt(readLine());

    function maxNumberOfPointsForWin(numberOfCards, numberOfJokers, numberOfPlayers) {
        var numberOfPlayerCards = numberOfCards / numberOfPlayers;
        var winnerJokerCards = Math.min(numberOfJokers, numberOfPlayerCards);
        var remainingJokers = numberOfJokers - winnerJokerCards;
        var maxPlayerPoints = Math.ceil(Math.min(remainingJokers / (numberOfPlayers - 1), numberOfPlayerCards));

        return winnerJokerCards - maxPlayerPoints;
    }

    for (var i = 0; i < testCases; i++) {
        var numbers = readLine()
            .split(" ")
            .map(num => parseInt(num));

        var numberOfCards = numbers[0];
        var numberOfJokers = numbers[1];
        var numberOfPlayers = numbers[2];

        console.log(maxNumberOfPointsForWin(numberOfCards, numberOfJokers, numberOfPlayers));
    }
}

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

const store = {};

function main() {
	let t = readLine() >> 0;

	while (t--) {
		let [n, m, k] = readLine()
			.split(' ')
			.map(x => x >> 0);

		let c = n / k;

		if (m === 0) {
			console.log(0);
			continue;
		}

		if (m <= c) {
			console.log(m);
			continue;
		}

		let r = m - c;
		let res = c;

		if (r % (k - 1) > 0) {
			res -= Math.floor(r / (k - 1)) + 1;
		} else {
			res -= Math.floor(r / (k - 1));
		}

		console.log(res);
	}
}

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

let index = 0;

readline.on('line', line => {
  index++;
  if (index > 1) {
    const [cards, jokers, players] = line.split(' ');
    const cardsPerPlayer = cards/players;
    if (cardsPerPlayer >= jokers) {
      console.log(jokers);
      return;
    }
    const maxOtherPlayerCards = Math.ceil((jokers - cardsPerPlayer) / (players - 1));
    console.log(cardsPerPlayer - maxOtherPlayerCards);
    return;
  }
});

/**

12, 7, 3
J,J,J,J
J,J
J

(12/3 = 4) => (4 < 7) => (7-4 = 3) => (ceil(3/2) = 2)
 */

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    m = input[1],
    k = input[2];

  var cards = n / k;
  if (m == 0) print(0);
  else if (cards >= m) print(m);
  else {
    m -= cards;
    var players = k - 1;
    var count = 1;
    var round = 0;
    while (m > 0 && count <= cards * players) {
      if (round == players) {
        round = 0;
        count++;
      }
      m--;
      round++;
    }

    print(cards - count);
  }
}

var testCases = readline();
for(var i =0; i< testCases; i++) {
    var line =  readline().split(" ");
    var cards = line[0], jokers = line[1], players = line[2];
    var cardsPerUser = cards/players;
    var maxJokers = cardsPerUser < jokers ? cardsPerUser : jokers;
    var leftJokers = jokers - maxJokers;
    print(maxJokers - Math.ceil(leftJokers/ (players - 1)));
}

function solve(n,m,k) {
    var c = n/k;
    var mn = Math.min(c,m);
    var d = m-mn;
    d = Math.ceil(d/(k-1));
    return mn-d;
}
var t = Number(readline());
while (t--) {
    var arr = readline().split(' ').map(Number);
    var n = arr[0];
    var m = arr[1];
    var k = arr[2];
    print(solve(n,m,k));
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    m = input[1],
    k = input[2];

  var cards = n / k;
  if (m == 0) print(0);
  else if (cards >= m) print(m);
  else {
    var players = k - 1;
    var count = 1;
    var round = 0;
    while (m > 0 && count * players <= cards) {
      if (round == players) {
        round = 0;
        count++;
        m--;
        continue;
      }
      m--;
      round++;
    }

    print(cards - count);
  }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    m = input[1],
    k = input[2];

  var cards = n / k;
  if (m == 0) print(0);
  else if (cards >= m) print(m);
  else {
    var players = k - 1;
    var count = 1;
    var round = 1;
    while (m > 0 && count * players <= cards) {
      if (round == players) {
        round = 1;
        count++;
        m--;
        continue;
      }
      m--;
      round++;
    }

    print(cards - count);
  }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    m = input[1],
    k = input[2];

  var cards = n / k;
  if (m == 0) print(0);
  else if (cards >= m) print(m);
  else {
    var players = k - 1;
    var count = 1;
    var round = 0;
    while (m > 0 && count <= cards * players) {
      if (round == players) {
        round = 0;
        count++;
        m--;
        continue;
      }
      m--;
      round++;
    }

    print(cards - count);
  }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    m = input[1],
    k = input[2];

  var cards = n / k;
  if (m == 0) print(0);
  else if (cards >= m) print(m);
  else {
    m -= cards;
    var players = k - 1;
    var count = 1;
    var round = 0;
    while (m > 0 && count <= cards * players) {
      if (round == players) {
        round = 0;
        count++;
        m--;
        continue;
      }
      m--;
      round++;
    }

    print(cards - count);
  }
}

function solve(n,m,k) {
    var c = n/k;
    var mn = Math.min(c,m);
    var d = m-mn;
    d = Math.ceil(d/(k-1));
    return c-d;
}
var t = Number(readline());
while (t--) {
    var arr = readline().split(' ').map(Number);
    var n = arr[0];
    var m = arr[1];
    var k = arr[2];
    print(solve(n,m,k));
}


Tanya has $$$n$$$ candies numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th candy has the weight $$$a_i$$$.She plans to eat exactly $$$n-1$$$ candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day.Your task is to find the number of such candies $$$i$$$ (let's call these candies good) that if dad gets the $$$i$$$-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. Note that at first, she will give the candy, after it she will eat the remaining candies one by one.For example, $$$n=4$$$ and weights are $$$[1, 4, 3, 3]$$$. Consider all possible cases to give a candy to dad:  Tanya gives the $$$1$$$-st candy to dad ($$$a_1=1$$$), the remaining candies are $$$[4, 3, 3]$$$. She will eat $$$a_2=4$$$ in the first day, $$$a_3=3$$$ in the second day, $$$a_4=3$$$ in the third day. So in odd days she will eat $$$4+3=7$$$ and in even days she will eat $$$3$$$. Since $$$7 \ne 3$$$ this case shouldn't be counted to the answer (this candy isn't good).  Tanya gives the $$$2$$$-nd candy to dad ($$$a_2=4$$$), the remaining candies are $$$[1, 3, 3]$$$. She will eat $$$a_1=1$$$ in the first day, $$$a_3=3$$$ in the second day, $$$a_4=3$$$ in the third day. So in odd days she will eat $$$1+3=4$$$ and in even days she will eat $$$3$$$. Since $$$4 \ne 3$$$ this case shouldn't be counted to the answer (this candy isn't good).  Tanya gives the $$$3$$$-rd candy to dad ($$$a_3=3$$$), the remaining candies are $$$[1, 4, 3]$$$. She will eat $$$a_1=1$$$ in the first day, $$$a_2=4$$$ in the second day, $$$a_4=3$$$ in the third day. So in odd days she will eat $$$1+3=4$$$ and in even days she will eat $$$4$$$. Since $$$4 = 4$$$ this case should be counted to the answer (this candy is good).  Tanya gives the $$$4$$$-th candy to dad ($$$a_4=3$$$), the remaining candies are $$$[1, 4, 3]$$$. She will eat $$$a_1=1$$$ in the first day, $$$a_2=4$$$ in the second day, $$$a_3=3$$$ in the third day. So in odd days she will eat $$$1+3=4$$$ and in even days she will eat $$$4$$$. Since $$$4 = 4$$$ this case should be counted to the answer (this candy is good). In total there $$$2$$$ cases which should counted (these candies are good), so the answer is $$$2$$$.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of candies. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^4$$$), where $$$a_i$$$ is the weight of the $$$i$$$-th candy.

Print one integer — the number of such candies $$$i$$$ (good candies) that if dad gets the $$$i$$$-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days.

NoteIn the first example indices of good candies are $$$[1, 2]$$$.In the second example indices of good candies are $$$[2, 3]$$$.In the third example indices of good candies are $$$[4, 5, 9]$$$.

var nums = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nums[0];
var s = readline().split(" ").map(function(x) { return parseInt(x); });

var od = Array(n).fill(0);
var ev = Array(n).fill(0);
od[0] = 0, ev[0] = s[0];
for (var i=1; i<n; i++) {
	od[i] = od[i-1];
	if (i%2===1) od[i] += s[i];
	ev[i] = ev[i-1];
	if (i%2===0) ev[i] += s[i];
}

var od2 = Array(n).fill(0);
var ev2 = Array(n).fill(0);
od2[n-1] = 0, ev2[n-1] = s[n-1];
for (var i=n-2; i>=0; i--) {
	od2[i] = od2[i+1];
	if ((n-1-i)%2===1) od2[i] += s[i];
	ev2[i] = ev2[i+1];
	if ((n-1-i)%2===0) ev2[i] += s[i];
}

var ans = 0;
for (var i=0; i<n; i++) {
	var od_sum = 0;
	if (i > 0) od_sum += od[i-1];
	var ev_sum = 0;
	if (i > 0) ev_sum += ev[i-1];

	if (i+1 < n) {
		if (n%2 == 1) {
			ev_sum += od2[i+1];
			od_sum += ev2[i+1];
		}
		else {
			ev_sum += ev2[i+1];
			od_sum += od2[i+1];
		}
	}

	if (od_sum === ev_sum)
		ans++;
}
write(ans+"\n");

var n = parseInt(readline())
var ar = readline().split(' ').map((v)=>(parseInt(v)))

var evenSum = [], prv=0;
ar.forEach((v, i)=>{

    evenSum[i] = (i%2===0) ? v+prv: prv
    prv = evenSum[i];
});

var oddSum = [];
prv =0;
ar.forEach((v, i)=>{

    oddSum[i] = (i%2!==0) ? v+prv: prv
    prv = oddSum[i];
});

var res = 0, currentEvenSum = -1, currentOddSum=0;
for(var i=0;i<ar.length;i++) {
    currentEvenSum = (i>0 ? evenSum[i-1]:0) + oddSum[evenSum.length-1] - oddSum[i] //-ar[i]?i%2
    currentOddSum = (i>0 ? oddSum[i-1]:0) + evenSum[evenSum.length-1] - evenSum[i]
    if (currentEvenSum === currentOddSum) {
        res++;
    }
}

print(res)

var n = parseInt(readline());
var a = readline().split(" ").map(function(element) {return +element});
var sum = [];
var sumAll = [0, 0];
sum.push([0]);
sum.push([0]);
for (var i=0; i < n; i++) {
    var index = i % 2;
    sumAll[index] += a[i];
    sum[index].push(sumAll[index]);
}
var count = 0;
var s = sumAll[0] + sumAll[1];
for (var i = 1; i < sum[0].length; i++) {
    var sum1 = sum[0][i - 1] + sumAll[1] - sum[1][i - 1];
    var sum2 = s - sum1 - a[(i - 1) * 2];
    if (sum1 === sum2) {
        count++;
    }
}

for (var i = 1; i < sum[1].length; i++) {
    var sum1 = sum[1][i - 1] + (i < sum[0].length ? sumAll[0] - sum[0][i] : 0);
    var sum2 = s - sum1 - a[i * 2 - 1];
    if (sum1 === sum2) {
        count++;
    }
}
print(count);

function calc(arr) {
  // calc (odd - even) to the left
  var arrLeft = [0];
  var curSum = 0;
  for (var i = 1; i < arr.length; i++) {
    curSum += arr[i - 1] * (i % 2 ? 1 : -1);
    arrLeft.push(curSum);
  }
  // print(arrLeft);

  // calc (odd - even) to the right
  var arrRight = [0];
  curSum = 0;
  for (var i = arr.length - 2; i > -1; i--) {
    curSum += arr[i + 1] * (i % 2 ? -1 : 1)
    arrRight.push(curSum);
  }
  arrRight.reverse();
  // print(arrRight);

  var res = 0;
  for (var i = 0; i < arr.length; i++) {
    if (arrLeft[i] + arrRight[i] === 0) {
      res++;
    }
  }

  return res;
}

var n = parseInt(readline());

var arr = readline().split(" ").map(el => parseInt(el));

print(calc(arr));

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const n = parseInt(arr.shift())
  const ar1 = arr[0].split(' ')
  const ar = []
  ar1.forEach(el => ar.push(parseInt(el)))

  let odd = 0, even = 0
  for(let i = 0, len = ar.length; i < len; i++) {
    if(i % 2 == 0) even += ar[i]
    else odd += ar[i]
  }

  var oB = 0, eB = 0
  var count = 0

  for(let i = 0, len = ar.length; i < len; i++) {
    if(i % 2 == 0) {
      var oA = even - ar[i] - eB
      var eA = odd - oB
      if(oA + oB == eA + eB) count ++
      eB += ar[i]
    }
    else {
      var oA = even - eB
      var eA = odd - ar[i] - oB
      if(oA + oB == eA + eB) count ++
      oB += ar[i]
    }
  }

  console.log(count)
})