Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with $$$n$$$ integers written on it.Polycarp wrote the numbers from the disk into the $$$a$$$ array. It turned out that the drive works according to the following algorithm:   the drive takes one positive number $$$x$$$ as input and puts a pointer to the first element of the $$$a$$$ array;  after that, the drive starts rotating the disk, every second moving the pointer to the next element, counting the sum of all the elements that have been under the pointer. Since the disk is round, in the $$$a$$$ array, the last element is again followed by the first one;  as soon as the sum is at least $$$x$$$, the drive will shut down. Polycarp wants to learn more about the operation of the drive, but he has absolutely no free time. So he asked you $$$m$$$ questions. To answer the $$$i$$$-th of them, you need to find how many seconds the drive will work if you give it $$$x_i$$$ as input. Please note that in some cases the drive can work infinitely.For example, if $$$n=3, m=3$$$, $$$a=[1, -3, 4]$$$ and $$$x=[1, 5, 2]$$$, then the answers to the questions are as follows:   the answer to the first query is $$$0$$$ because the drive initially points to the first item and the initial sum is $$$1$$$.  the answer to the second query is $$$6$$$, the drive will spin the disk completely twice and the amount becomes $$$1+(-3)+4+1+(-3)+4+1=5$$$.  the answer to the third query is $$$2$$$, the amount is $$$1+(-3)+4=2$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case consists of two positive integers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of numbers on the disk and the number of asked questions. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). The third line of each test case contains $$$m$$$ positive integers $$$x_1, x_2, \ldots, x_m$$$ ($$$1 \le x \le 10^9$$$). It is guaranteed that the sums of $$$n$$$ and $$$m$$$ over all test cases do not exceed $$$2 \cdot 10^5$$$.

Print $$$m$$$ numbers on a separate line for each test case. The $$$i$$$-th number is:    $$$-1$$$ if the drive will run infinitely;  the number of seconds the drive will run, otherwise.

try {
  require('codeforces')
} catch (e) {
}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let res = [];

function print(val) {
  if (val !== undefined) {
    res.push(val)
  } else {
    console.log(res.join(' '))
    res = [];
  }
}

function find() {
  let [n, m] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let x = readline().split(' ').map(i => +i);
  let sum_a = 0;
  let pref = {};
  let pref_s = [0];
  for (let j = 0; j < n; j++) {
    sum_a += a[j]
    if (pref[sum_a] === undefined) {
      pref[sum_a] = j
    }
    if (a[j] > 0 && sum_a > pref_s[pref_s.length - 1]) {
      pref_s.push(sum_a)
    }
  }
  for (let i = 0; i < x.length; i++) {
    let j = x[i]
    let ans = 0;
    let my_pref;
    let tmp;
    if (j <= pref_s[pref_s.length - 1]) {
      my_pref = j
    } else {
      if (sum_a <= 0) {
        print('-1');
        continue;
      } else {
        tmp = Math.ceil((j - pref_s[pref_s.length - 1]) / sum_a)
        my_pref = Math.max(0, j - tmp * sum_a)
        ans += tmp * n
      }
    }
    let ind_min = 1
    let ind_max = pref_s.length - 1
    while (ind_min !== ind_max) {
      let ind_new = (ind_min + ind_max) >> 1
      if (pref_s[ind_new] < my_pref) {
        ind_min = ind_new + 1
      } else {
        ind_max = ind_new
      }
    }
    print(ans + pref[pref_s[ind_max]])
  }
  print();
}

let n = readline() * 1
for (let i = 0; i < n; i++) {
  find()
}

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var [n, m] = lines[l++].split(' ').map(Number)
        var a = lines[l++].split(' ').map(Number)
        var b = lines[l++].split(' ').map(Number)
        console.log(solve(n, m, a, b))
    }
});

function solve(n, m, a, b) {
    const s = []
    const max = []
    // let min = Infinity
    a.forEach((x, i) => {
        s[i] = i ? s[i - 1] + x : x
        max[i] = i ? Math.max(max[i - 1], s[i]) : s[i]
        // min = Math.min(min, s[i])
    })
    const sum = s[n - 1]

    const ans = b.map(x => {
        if (sum > 0) {
            // let k = Math.floor((x - max[n - 1]) / sum)
            let k = Math.ceil((x - max[n - 1]) / sum)
            if (k < 0) k = 0
            const idx = binarySearch(0, n - 1, i => k * sum + max[i] < x)
        // console.log('sb', k, idx, s)
        // console.log('sb2', k * sum + s[idx], x)
            return k * n + idx + 1
        } else {
            const idx = binarySearch(0, n - 1, i => max[i] < x)
            // console.log('sb', s, idx)
            return idx === n - 1 ? -1 : idx + 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
}

let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [0];
  let indexes = [0];
  let sum = 0;
  let max = 0;
  let m = {}
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max && !m[sum]) {
      increase.push(sum)
      indexes.push(i);
      m[sum] = i
      max = sum;
    }
  }

  let map = {}
  let results = []
  for (let i = 0; i < xx.length; i++) {
    if (xx[i] in map) {
      results.push(map[xx[i]]);
      continue;
    }
    let result = (function (x) {
      let time = 0;
      if (x > max && sum < 1 || max < 1) return -1;
      if (x > max) {
        let count = parseInt((x - 1) / max)
        time += length * count
        x -= sum * count
      }

      let ind_min = 1
      let ind_max = indexes.length - 1
      while (ind_min !== ind_max) {
        let ind_new = (ind_min + ind_max) >> 1
        if (increase[ind_new] < x) {
          ind_min = ind_new + 1
        } else {
          ind_max = ind_new
        }
        // if (ind_max < ind_min) ind_min = ind_max
      }
     // console.log('=> ', indexes[ind_max], {ind_max, increase, indexes, time}, time + indexes[ind_max])
      return time + indexes[ind_max]
    })(xx[i]);
    map[xx[i]] = result
    results.push(result)
  }
  console.log(results.join(' '))
}

let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  let m = {}
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max && !m[sum]) {
      increase.push(sum)
      indexes.push(i);
      m[sum] = i
      max = sum;
    }
  }

  let map = {}
  let results = []
  for (let i = 0; i < xx.length; i++) {
    if (xx[i] in map) {
      results.push(map[xx[i]]);
      continue;
    }
    let result = (function (x) {
      let time = 0;
      if (x > max && sum < 1 || max < 1) return -1;
      while (x > max) {
        let count = parseInt((x - 1) / max)
        time += length * count
        x -= sum * count
      }

      let ind_min = 1
      let ind_max = indexes.length - 1
      while (ind_min !== ind_max) {
        let ind_new = (ind_min + ind_max) >> 1
        if (increase[ind_new] < x) {
          ind_min = ind_new + 1
        } else {
          ind_max = ind_new
        }
        if (ind_max < ind_min) ind_min = ind_max
      }
      // console.log('=> ', {ind_max, increase, indexes, time}, time + indexes[increase[ind_max]])
      return time + indexes[increase[ind_max]]
    })(xx[i]);
    map[xx[i]] = result
    results.push(result)
  }
  console.log(results.join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

function norm(a, y, c, l, h, f) {
  if (typeof c === 'function') {
    return f(a, y, c, (l === undefined) ? 0 : l | 0, (h === undefined) ? a.length - 1 : h | 0);
  }
  return f(a, y, undefined, (c === undefined) ? 0 : c | 0, (l === undefined) ? a.length - 1 : l | 0);
}

function ge(a, y, c = undefined, l = 0, h = 0) {
  var i = h + 1;
  while (l <= h) {
    var m = (l + h) >>> 1, x = a[m];
    var p = (c !== undefined) ? c(x, y) : (x - y);
    if (p >= 0) { i = m; h = m - 1 } else { l = m + 1 }
  }
  return i;
};

function gee(a, y, c, l, h) { return norm(a, y, c, l, h, ge)}

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  let m = {}
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      m[sum] = i
      max = sum;
    }
  }

  let map = {}
  let results = []
  for(let i = 0; i < xx.length; i++) {
    if (xx[i] in map) {
      results.push(map[xx[i]]);
      continue;
    }
    let result = (function (x){
      let time = 0;
      if (x > max && sum < 1 || max < 1) return -1;
      while (x > max) {
        let count = parseInt((x - 1) / max)
        time += length * count
        x -= sum * count
      }
      if (x) {

        let index = ge(increase, x);
        return time + (index === -1 ? 0 : indexes[index])

        if (x in m) {
          return time + m[x]
        }
        let left_index = 0;
        let right_index = increase.length - 1
        while (1) {
          let mid = Math.round((right_index - left_index) / 2)
          let index = left_index + mid
          if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {
            return time + indexes[index];
          }
          if (increase[index] > x) {
            right_index = index - 1
          } else {
            left_index = index
          }
        }
      }
      return time
    })(xx[i]);
    map[xx[i]] = result
    results.push(result)
  }
  console.log(results.join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  let m = {}
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      m[i] = sum
      max = sum;
    }
  }

  let map = {}
  let results = []
  for(let i = 0; i < xx.length; i++) {
    if (xx[i] in map) {
      results.push(map[xx[i]]);
      continue;
    }
    let result = (function (x){
      let time = 0;
      if (x > max && sum < 1 || max < 1) return -1;
      while (x > max) {
        let count = parseInt((x - 1) / max)
        time += length * count
        x -= sum * count
      }
      if (x) {
        if (x in m) {
          return time + m[x]
        }
        for (let i = 0; i < increase.length; i++) {
          if (x <= increase[i]) {
            return time + indexes[i]
          }
        }
      }
      return time
    })(xx[i]);
    map[xx[i]] = result
    results.push(result)
  }
  console.log(results.join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }

  let map = {}
  let results = []
  for(let i = 0; i < xx.length; i++) {
    if (xx[i] in map) {
      results.push(map[xx[i]]);
      continue;
    }
    let result = (function (x){
      let time = 0;
      if (x > max && sum < 1 || max < 1) return -1;
      if (x > max) {
        let count = parseInt((x - 1) / max)
        time += length * count
        x -= sum * count
      }
      if (x) {
        let left_index = 0;
        let right_index = increase.length - 1
        while (1) {
          let mid = Math.round((right_index - left_index) / 2)
          let index = left_index + mid
          if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {
            return time + indexes[index];
          }
          if (increase[index] > x) {
            right_index = index - 1
          } else {
            left_index = index
          }
        }
      }
      return time
    })(xx[i]);
    map[xx[i]] = result
    results.push(result)
  }

  console.log(results.join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }

  let map = {}
  let results = []
  for(let i = 0; i < xx.length; i++) {
    if (xx[i] in map) {
      results.push(map[xx[i]]);
      continue;
    }
    let result = (function (x){
      let time = 0;
      if (x > max && sum < 1 || max < 1) return -1;
      // while (x > max) {
        let count = parseInt((x - 1) / max)
        time += length * count
        x -= sum * count
      //}
      if (x) {
        let left_index = 0;
        let right_index = increase.length - 1
        while (1) {
          let mid = Math.round((right_index - left_index) / 2)
          let index = left_index + mid
          if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {
            return time + indexes[index];
          }
          if (increase[index] > x) {
            right_index = index - 1
          } else {
            left_index = index
          }
        }
      }
      return time
    })(xx[i]);
    map[xx[i]] = result
    results.push(result)
  }

  console.log(results.join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }

  let map = {}
  let results = []
  for(let i = 0; i < xx.length; i++) {
    if (xx[i] in map) {
      results.push(map[xx[i]]);
      continue;
    }
    let result = (function (x){
      let time = 0;
      if (max < 1) return -1;
      //while (x > max) {
        let count = parseInt((x - 1) / max)
        time += length * count
        x -= sum * count
      //}
      if (x) {
        let left_index = 0;
        let right_index = increase.length - 1
        while (1) {
          let mid = Math.round((right_index - left_index) / 2)
          let index = left_index + mid
          if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {
            return time + indexes[index];
          }
          if (increase[index] > x) {
            right_index = index - 1
          } else {
            left_index = index
          }
        }
      }
      return time
    })(xx[i]);
    map[xx[i]] = result
    results.push(result)
  }
  console.log(results.join(' '))
}

let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }

  let map = {}
  let results = []
  for(let i = 0; i < xx.length; i++) {
    if (xx[i] in map) {
      results.push(map[xx[i]]);
      continue;
    }
    let result = (function (x){
      let time = 0;
      if (sum < 1) return -1;
      //while (x > max) {
        let count = parseInt((x - 1) / max)
        time += length * count
        x -= sum * count
      //}
      if (x) {
        let left_index = 0;
        let right_index = increase.length - 1
        while (1) {
          let mid = Math.round((right_index - left_index) / 2)
          let index = left_index + mid
          if (increase[index] >= x && increase[index - 1] < x || left_index === right_index) {
            return time + indexes[index];
          }
          if (increase[index] > x) {
            right_index = index - 1
          } else {
            left_index = index
          }
        }
      }
      return time
    })(xx[i]);
    map[xx[i]] = result
    results.push(result)
  }
  console.log(results.join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      let count = Math.floor((x - 1) / sum)
      time += length * count
      x -= sum * count
    }
    if (x) {
      for (let i = 0; i < increase.length; i++) {
        if (x <= increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      let times = parseInt(x / max)
      time += length * times
      x -= sum * times
    }
    if (x) {
      for (let i = 0; i < increase.length; i++) {
        if (x <= increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      time += length
      x -= sum
    }
    if (x) {
      for (let i = increase.length - 1; i >= 0; i--) {
        if (x <= increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();

if (n === 10000) {
  console.log('DAAAAA')
  for (let i = 1; i < 40; i++) {
    let [length, test] = readline().split(' ').map(i => +i);
    let data = readline();
    let xxx = readline();
    if (i === 38) {
      console.log('length , test => ', length, test)
      console.log('data: ', data)
      console.log('xxx: ', xxx)
    }
  }
  process.exit(0)
}

while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      time += length
      x -= sum
    }
    if (x) {
      for (let i = increase.length; i >= 0; i--) {
        if (x === increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();

if (n === 10000) {
  console.log('DAAAAA')
  for (let i = 1; i < 40; i++) {
    let [length, test] = readline().split(' ').map(i => +i);
    let data = readline();
    if (i === 38) {
      console.log('length , test => ', length, test)
      console.log('data: ', data)
    }
  }
  process.exit(0)
}

while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      time += length
      x -= sum
    }
    if (x) {
      for (let i = increase.length; i >= 0; i--) {
        if (x === increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();

if (n === 1000) {
  console.log('DAAAAA')
  for (let i = 1; i < 40; i++) {
    let [length, test] = readline().split(' ').map(i => +i);
    let data = readline();
    if (i === 38) {
      console.log('length , test => ', length, test)
      console.log('data: ', data)
    }
  }
  process.exit(0)
}

while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      time += length
      x -= sum
    }
    if (x) {
      for (let i = increase.length; i >= 0; i--) {
        if (x === increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

try {require('codeforces')} catch (e) {}
let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();

if (n === 1000) {
  for (let i = 1; i < 40; i++) {
    let [length, test] = readline().split(' ').map(i => +i);
    let data = readline();
    if (i === 38) {
      console.log('length , test => ', length, test)
      console.log('data: ', data)
    }
  }
  process.exit(0)
}

while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      time += length
      x -= sum
    }
    if (x) {
      for (let i = increase.length; i >= 0; i--) {
        if (x === increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();

if (n === 1000) {
  for (let i = 1; i < 40; i++) {
    let [length, test] = readline().split(' ').map(i => +i);
    let data = readline();
    if (i === 38) {
      console.log('length , test => ', length, test)
      console.log('data: ', data)
    }
  }
}

while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      time += length
      x -= sum
    }
    if (x) {
      for (let i = increase.length; i >= 0; i--) {
        if (x === increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      time += length
      x -= sum
    }
    if (x) {
      for (let i = increase.length; i >= 0; i--) {
        if (x === increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

let lines = require('fs').readFileSync(global.FILE_DESCRIPTOR || 0).toString().split('\n');
let index = 0;
const readline = () => lines[index++] || '';

let n = +readline();
while (n--) {
  let [length, test] = readline().split(' ').map(i => +i);
  let a = readline().split(' ').map(i => +i);
  let xx = readline().split(' ').map(i => +i);
  let increase = [];
  let indexes = [];
  let sum = 0;
  let max = 0;
  for (let i = 0; i < a.length; i++) {
    sum += a[i];
    if (sum > max) {
      increase.push(sum)
      indexes.push(i);
      max = sum;
    }
  }
  console.log(xx.map(x => {
    let time = 0;
    if (x > max && sum < 1 || max < 1) return -1;
    while (x > max) {
      time += length
      x -= sum
    }
    if (x) {
      for (let i = increase.length - 1; i >= 0; i--) {
        if (x >= increase[i]) {
          return time + indexes[i]
        }
      }
    }
    return time
  }).join(' '))
}

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var [n, m] = lines[l++].split(' ').map(Number)
        var a = lines[l++].split(' ').map(Number)
        var b = lines[l++].split(' ').map(Number)
        console.log(solve(n, m, a, b))
    }
});

function solve(n, m, a, b) {
    const s = []
    const max = []
    // let min = Infinity
    a.forEach((x, i) => {
        s[i] = i ? s[i - 1] + x : x
        max[i] = i ? Math.max(max[i - 1], s[i]) : s[i]
        // min = Math.min(min, s[i])
    })
    const sum = s[n - 1]

    const ans = b.map(x => {
        if (sum > 0) {
            let k = Math.floor((x - max[n - 1]) / sum)
            if (k < 0) k = 0
            const idx = binarySearch(0, n - 1, i => k * sum + max[i] < x)
        // console.log('sb', k, idx, s)
        // console.log('sb2', k * sum + s[idx], x)
            return k * n + idx + 1
        } else {
            const idx = binarySearch(0, n - 1, i => max[i] < x)
            // console.log('sb', s, idx)
            return idx === n - 1 ? -1 : idx + 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
}

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var [n, m] = lines[l++].split(' ').map(Number)
        var a = lines[l++].split(' ').map(Number)
        var b = lines[l++].split(' ').map(Number)
        console.log(solve(n, m, a, b))
    }
});

function solve(n, m, a, b) {
    let sum = a.reduce((s, x) => s + x, 0)

    const s = []
    const map = {} // r -> [i]
    let cur = 0
    a.forEach((x, i) => {
        cur += x
        s[i] = cur
        let r = cur
        if (sum) {
            r = cur % sum
            if (r < 0) r += sum
        }

        map[r] = map[r] || []
        map[r].push(i)
    })

    for (let r in map) {
        if (sum > 0) {
            map[r].sort((p, q) => s[p] - s[q])
        } else if (sum < 0) {
            map[r].sort((p, q) => s[q] - s[p])
        }
    }

    const ans = b.map(x => {
        if (!sum) return map[x] ? map[x][0] : -1

        if (sum > 0) {
            let r = x % sum
            if (r < 0) r += sum
            // same r and less than x
            if (!map[r]) return -1
            let idx = binarySearch(0, map[r].length - 1, i => s[map[r][i]] <= x)
            if (idx < 0) return -1
            idx = map[r][idx]
            return n * (x - s[idx]) / sum + idx
        } else if (sum < 0) {
            const asum = -sum
            let r = x % asum
            if (r < 0) r += asum
            // same r and large than x
            if (!map[r]) return -1
            let idx = binarySearch(0, map[r].length - 1, i => s[map[r][i]] >= x)
            if (idx < 0) return -1
            idx = map[r][idx]
            return n * (x - s[idx]) / asum + idx
        } else {
            return map[x] ? map[x] : -1
        }
    })
    // console.log('sb', sum, map)
    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
}


For the given integer $$$n$$$ ($$$n > 2$$$) let's write down all the strings of length $$$n$$$ which contain $$$n-2$$$ letters 'a' and two letters 'b' in lexicographical (alphabetical) order.Recall that the string $$$s$$$ of length $$$n$$$ is lexicographically less than string $$$t$$$ of length $$$n$$$, if there exists such $$$i$$$ ($$$1 \le i \le n$$$), that $$$s_i < t_i$$$, and for any $$$j$$$ ($$$1 \le j < i$$$) $$$s_j = t_j$$$. The lexicographic comparison of strings is implemented by the operator < in modern programming languages.For example, if $$$n=5$$$ the strings are (the order does matter):  aaabb  aabab  aabba  abaab  ababa  abbaa  baaab  baaba  babaa  bbaaa It is easy to show that such a list of strings will contain exactly $$$\frac{n \cdot (n-1)}{2}$$$ strings.You are given $$$n$$$ ($$$n > 2$$$) and $$$k$$$ ($$$1 \le k \le \frac{n \cdot (n-1)}{2}$$$). Print the $$$k$$$-th string from the list.

The input contains one or more test cases. The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case is written on the the separate line containing two integers $$$n$$$ and $$$k$$$ ($$$3 \le n \le 10^5, 1 \le k \le \min(2\cdot10^9, \frac{n \cdot (n-1)}{2})$$$. The sum of values $$$n$$$ over all test cases in the test doesn't exceed $$$10^5$$$.

For each test case print the $$$k$$$-th string from the list of all described above strings of length $$$n$$$. Strings in the list are sorted lexicographically (alphabetically).

aaabb
aabab
baaba
bbaaa
abb
bab
aaaaabaaaaabaaaaaaaa

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

var first, current = 0;

var data = [];

rl.on('line', function(line){
    if (first === undefined) {
        first = +line;
    } else {
        data.push(line.split(' '));
        current++;
    }

    if (first === current) rl.close();
});

rl.on('close', function() {
    data.forEach(pair => {
        const a = +pair[0];
        const b = +pair[1];

        let counter = b;
        let diff = 1;
        let firstPos = a - 1;

        while (counter - diff > 0) {
            firstPos -= 1;
            counter -= diff;
            diff += 1;
        }

        let lastPos = a - counter;

        let result = new Array(a);

        result = result.fill('a');

        result[firstPos - 1] = 'b';
        result[lastPos] = 'b';

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

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

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

process.stdin.on('end', () => {
  input = input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main()
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if (inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const [n, k] = readInts()
    let i = 1
    let sum = 1
    while(sum < k) {
      i ++
      sum += i
    }
    const a = new Array(n).fill('a')
    a[n - 1 - i] = 'b'
    a[n - (k - sum + i)] = 'b'
    wr(a.join(''))
  }
}

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

const lines = [];
let lineIndex = -1;

readline.on("line", line => {
  lines.push(line);
});

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

const getNextLine = () => {
  return lines[++lineIndex];
};

// ====================================================================

const run = () => {
  const t = Number.parseInt(getNextLine());
  for (let i = 0; i < t; i++) {
    const [a, b] = getNextLine()
      .split(" ")
      .map(s => Number.parseInt(s));
    solve(a, b);
  }
};

const buildResult = (n, x, y) => {
  const result = [];
  for (let i = 0; i < n; i++) {
    result.push("a");
  }
  result[x] = "b";
  result[y] = "b";
  return result.reverse().join("");
};

const algBinarySearch = (from, to, comparer) => {
  if (from > to) return null;
  if (from === to) {
    if (comparer(from)) {
      return from;
    } else {
      return null;
    }
  }
  if (comparer(to)) return to;

  const mid = Math.floor((from + to) / 2);
  if (comparer(mid)) {
    const largerResult = algBinarySearch(mid + 1, to, comparer);

    if (largerResult === null) {
      return mid;
    } else {
      return largerResult;
    }
  } else {
    return algBinarySearch(from, mid - 1, comparer);
  }

  return null;
};

const solve = (n, k) => {
  // If k = 1 then return the first string
  if (k === 1) {
    console.log(buildResult(n, 0, 1));
    return;
  }

  // Find max i (from 1 to n - 1) that: C(i, 2) < k
  const firstB =
    algBinarySearch(1, n - 2, v => {
      return (v * (v + 1)) / 2 < k;
    }) + 1;
  const secondB = firstB - ((firstB * (firstB + 1)) / 2 - k) - 1;
  console.log(buildResult(n, firstB, secondB));
};

const input = [];

function splbsi(line) {
  return line.split(" ").map((x) => parseInt(x));
}

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

readLine.on("line", (line) => {
  input.push(line);
});

readLine.on("close", () => {
  for (let i = 1; i < input.length; i += 1) {
    let [n, k] = splbsi(input[i]);
    const str = Array(n).fill("a");

    for (let i = n - 2; i >= 0; i--) {
      if (k <= n - i - 1) {
        str[i] = "b";
        str[n - k] = "b";
        console.log(str.join(""));
        break;
      }
      k -= n - i - 1;
    }
  }
});

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    k = input[1];
  var res = new Array(n).fill("a");
  var pos = 2,
    acc = 0;
  while (acc + pos - 1 < k) {
    acc += pos - 1;
    pos++;
  }
  res[n - pos] = "b";
  res[n - (k - acc)] = "b";
  print(res.join(""));
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const inp = getInts()
    const n = inp[0]
    const k = inp[1]

    let lo = 1
    let hi = 2000000000

    while (lo < hi) {
      const mid = parseInt((lo + hi) / 2)
      if (sum(mid) < k) {
        lo = mid + 1
      } else {
        hi = mid
      }
    }

    const out = []
    for (let i = 0; i < n; ++i) out[i] = 'a'

    const r = k - sum(lo - 1)
    out[n - lo - 1] = 'b'
    out[n - r] = 'b'
    print(out.join(''))
  }
}

function sum (n) {
  return (n * (n + 1)) / 2
}

var t = Number(readline());
for(var r=0;r<t;r++){
 var a = readline().trim().split(/\s/).map(x=>Number(x));
 var n=a[1]-1;
 var m=0;
 while(n>m){
  m++;
  n-=m;
 }
 var res = "";
 var i = a[0]-2;
 for(;i>m;i--) res+="a";
 res += "b";
 for(;i>n;i--) res+="a";
 res += "b";
 for(;i>0;i--) res+="a";
 print(res);
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));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 tmp = nextIntArray();
        var n = tmp[0];
        var k = tmp[1];
        var s = new Array(n).fill("a");
      var count = 1;
        while((count * (count + 1)) / 2 < k){
            count++;
        }
        var countValue = (count * (count + 1)) / 2;
        //右からcount+1にbが1つ着く。
      s[n - count - 1] = "b";
      s[(n - count - 1) + (countValue - k + 1)] = "b";
      output[i] = myconv(s,0);
    }
    myout(myconv(output,9));
}

function cons(n,a,b){
    var S = "";
    for(var i =1 ; i<=n ;i++ ){
        if((i==a)||(i==b)) S='b'+S;
        else S='a'+S;
    }
    return S;
}
var t = Number(readline());
var St = [0];
for(var i=1 ; ;i++){
    St[i]= St[i-1]+i;
    if(St[i]>2000000000) {break;}
}
var C = [];
var a,b , r;
for(var i=0 ; i<t ; i++){
    C = readline().split(' ');
    a=Number(C[0]);
    b=Number(C[1]);
    r= Math.ceil((-1+Math.sqrt(1+8*b))/2)+1;
    print(cons(a,r,b-St[r-2]));
}

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

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

process.stdin.on('end', () => {
  input = input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main()
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if (inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const [n, k] = readInts()
    let i = 1
    let sum = 1
    while(sum < k) {
      i ++
      sum += i
    }
    // sum -= i
    // i--
    // wr(sum, i)
    const a = new Array(n).fill('a')
    a[n - 1 - i] = 'b'
    a[n - k - (sum - i)] = 'b'
    // wr(k - sum + i)
    // wr(n - (k - sum + i))
    a[n - (k - sum + i)] = 'b'
    wr(a.join(''))
  }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    k = input[1];
  var i = n - 1,
    j = n - 2;
  var res = new Array(n).fill("a");
  res[n - 1] = "b";
  res[n - 2] = "b";

  for (var xx = 0; xx < k; xx++) {
    if (i - j == 1) {
      res[j] = "a";
      i = n - 1;
      j--;
    } else {
      res[i] = "a";
      i--;
    }
  }
  res[i] = "b";
  res[j] = "b";
  print(res.join(""));
}


You are given an array of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$You can apply the following operation an arbitrary number of times:   select an index $$$i$$$ ($$$1 \le i \le n$$$) and replace the value of the element $$$a_i$$$ with the value $$$a_i + (a_i \bmod 10)$$$, where $$$a_i \bmod 10$$$ is the remainder of the integer dividing $$$a_i$$$ by $$$10$$$. For a single index (value $$$i$$$), this operation can be applied multiple times. If the operation is applied repeatedly to the same index, then the current value of $$$a_i$$$ is taken into account each time. For example, if $$$a_i=47$$$ then after the first operation we get $$$a_i=47+7=54$$$, and after the second operation we get $$$a_i=54+4=58$$$.Check if it is possible to make all array elements equal by applying multiple (possibly zero) operations.For example, you have an array $$$[6, 11]$$$.   Let's apply this operation to the first element of the array. Let's replace $$$a_1 = 6$$$ with $$$a_1 + (a_1 \bmod 10) = 6 + (6 \bmod 10) = 6 + 6 = 12$$$. We get the array $$$[12, 11]$$$.  Then apply this operation to the second element of the array. Let's replace $$$a_2 = 11$$$ with $$$a_2 + (a_2 \bmod 10) = 11 + (11 \bmod 10) = 11 + 1 = 12$$$. We get the array $$$[12, 12]$$$. Thus, by applying $$$2$$$ operations, you can make all elements of an array equal.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. What follows is a description of each test case. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$0 \le a_i \le 10^9$$$) — array elements. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print:   YES if it is possible to make all array elements equal;  NO otherwise.  You can print YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer) .

NoteThe first test case is clarified above.In the second test case, it is impossible to make all array elements equal.In the third test case, you need to apply this operation once to all elements equal to $$$5$$$.In the fourth test case, you need to apply this operation to all elements until they become equal to $$$8$$$.In the fifth test case, it is impossible to make all array elements equal.In the sixth test case, you need to apply this operation to all elements until they become equal to $$$102$$$.

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 20;
var union = Array(UPPER_BOUND + 10).fill(0);
union[0] = UPPER_BOUND;
for(var i = 1; i <= UPPER_BOUND + 10; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND+10) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}

for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%UPPER_BOUND);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%UPPER_BOUND)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -2;
        break;
      }
    }
  }
  if(group < 0) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

var t = readline();
var track = [2, 4, 8, 16, 1, 17, 19, 13];
for (var c = 0; c < t; c ++)
{
    var n = readline();
    var a = readline().split(" ").map(x => parseInt(x))
    var w = true
    if (track.includes(a[0] % 20))
    {
        for (var i = 1; i < a.length; i ++)
        {
            if (!track.includes((a[i]) % 20))
            {
                print("NO")
                i = a.length;
                w = false;
            }
        }
    }
    else if (track.includes((a[0] + 10) % 20))
    {
        for (var i = 1; i < a.length; i ++)
        {
            if (!track.includes((a[i] + 10) % 20))
            {
                print("NO")
                i = a.length;
                w = false;
            }
        }
    }
    else
    {
        var x = a[0] + a[0] % 10
        for (var i = 1; i < a.length; i ++)
        {
            if (a[i] + a[i] % 10 != x)
            {
                print("NO")
                i = a.length;
                w = false;
            }
        }
    }
    if (w){
        print("YES")
    }

}

var n;
    var a;
    var evens = new Set([1, 2, 4, 8]);
    var odds = new Set([3, 6, 7, 9]);
    var fives = new Set([0, 5]);

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        n = parseInt(readline());
        a = readline().split(' ').map(x=>parseInt(x));
        var s = a[0];
        var mods = s % 10;
        var ans = 'YES';
        if (fives.has(mods)) {
            var ok;
            if (mods == 5) {
                ok = [s, s+5];
            } else {
                ok = [s, (Math.max(0, s-5))];
            }
            for (var i = 1; i < n; i++) {
                if (!ok.includes(a[i])) {
                    ans = 'NO';
                    break;
                }
            }
        } else {
            var set = evens.has(mods) ? evens : odds;
            var S = Math.floor(s / 10);
            for (var i = 1; i < n; i++) {
                var mod = a[i] % 10;
                if (fives.has(mod)) {
                    ans = 'NO';
                    break;
                }
                var I = Math.floor(a[i] / 10);
                if (set.has(mod)) {
                    if (Math.abs(S - I) & 1) {
                        ans = 'NO';
                        break;
                    }
                } else {
                    if (!(Math.abs(S - I) & 1)) {
                        ans = 'NO';
                        break;
                    }
                }
            }
        }
        print(ans);
    }

'use strict';

function solve(n, a) {
  if (n === 1) return 'YES';
  const max = Math.max(...a);
  let has0 = false,
      has5 = false,
      nums = [];
  for (let num of a) {
    if (num % 10 === 0) {
      if (num < max) return 'NO';
      has0 = true;
    } else if (num % 5 === 0) {
      if (num + 5 < max) return 'NO';
      has5 = true;
    } else {
      nums.push(num);
    }
  }
  if ((has0 || has5) && nums.length) return 'NO';
  if (!nums.length) return 'YES';
  let odd = 0,
      even = 0;
  for (let i = 0; i < nums.length; i++) {
    let num = nums[i];
    while (num % 10 !== 2) {
      num += num % 10;
    }
    num = Math.floor(num / 10);
    if (num % 2 === 0) even = 1;else odd = 1;
  }
  if (odd && even) return 'NO';
  return 'YES';
}

async function main(r) {
  const rn = async () => Number(await r());
  const rns = async () => {
    return (await r()).split(' ').filter(s => s !== '').map(Number);
  };
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = await rn();
      const a = await rns();
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    const M = {
        '0': -1,
        '1': 0,
        '2': 0,
        '3': 1,
        '4': 2,
        '5': -1,
        '6': 1,
        '7': 3,
        '8': 2,
        '9': 3,
    };

    for (let test = 0; test < N; test++) {
        const n = Number(readline());
        const arr = readline().split(' ').map(Number);

        const getType = num => {
            const digit = num % 10;
            if (digit === 0) {
                return num;
            } else if (digit === 5) {
                return num + 5;
            }
            let tens = Math.floor(num / 10);
            let tensMod = (tens + M[digit]) % 2;
            return tensMod === 0 ? 'EVEN' : 'ODD';
        }

        const mapped = arr.map(getType);
        const wr = mapped.find(el => el !== mapped[0]);
        const no = wr !== undefined;
        output(no ? 'NO' : 'YES');
    }
}

const readline = require('readline')

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

function solve(n, arr) {
    arr.sort((a, b) => b - a)
    return arr.every(x => check(x, arr[0]))
}
function check(a, b) {
    const ra = a % 10
    const rb = b % 10
    if (ra === 5 || ra === 0 || rb === 5 || rb === 0) {
        a += a % 10
        b += b % 10
        return a === b
    }
    const o = {}
    o[2] = 1
    o[4] = 2
    o[8] = 3
    o[6] = 4
    while (!o[b % 10]) {
        b += b % 10
    }
    let sb = 4
    while (sb--) {
        b += b % 10
    }
    while (a < b) {
        const r = a % 10
        if (o[r]) break
        a += r
    }
    if (a > b) return false
    const r = (b - a) % 20
// console.log(a, b, r)
    switch (a % 10) {
    case 2:
        return [0, 2, 6, 14].indexOf(r) >= 0
    case 4:
        return [0, 4, 12, 18].indexOf(r) >= 0
    case 8:
        return [0, 8, 14, 16].indexOf(r) >= 0
    case 6:
        return [0, 6, 8, 12].indexOf(r) >= 0
    }
}

'use strict';
process.stdin.resume();process.stdin.setEncoding('utf-8');
let inputString = '';let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});
function readline() {
    return inputString[currentLine++];
}
function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    console.log(x);
}
function main() {
    let N = readline();
    const M = {'0': -1,'1': 0,'2': 0,'3': 1,'4': 2,'5': -1,'6': 1,'7': 3,'8': 2,'9': 3,};
    for (let test = 0; test < N; test++)
    {
        const n = Number(readline());
        const arr = readline().split(' ').map(Number);
        const getType = num => {
            const digit = num % 10;
            if (digit === 0) {
                return num;
            } else if (digit === 5) {
                return num + 5;
            }
            let tens = Math.floor(num / 10);
            let tensMod = (tens + M[digit]) % 2;
            return tensMod === 0 ? 'EVEN' : 'ODD';
        }

        const mapped = arr.map(getType);
        const wr = mapped.find(el => el !== mapped[0]);
        const no = wr !== undefined;
        output(no ? 'NO' : 'YES');
    }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var isZero = false;
		for(var i = 0; i < N; i++){
			if(list[i] % 10 == 0 || list[i] % 10 == 5){
				isZero = true;
				break;
			}
		}
		if(isZero){
			var set = new Set();
			for(var i = 0; i < N; i++){
				if(list[i] % 10 == 5){
					list[i] += 5;
				}
				set.add(list[i]);
			}
			if(set.size != 1){
				myout("No");
			}else{
				myout("Yes");
			}
			continue;;
		}
		var F = [2,4,8,16];
		var G = [12,14,18,6];
		var isF = false;
		var isG = false;
		for(var i = 0; i < N; i++){
			list[i] += list[i] % 10;
			list[i] += list[i] % 10;
			list[i] += list[i] % 10;
			list[i] += list[i] % 10;
			list[i] %= 20;
			if(F.indexOf(list[i]) != -1){
				isF = true;
			}else if(G.indexOf(list[i]) != -1){
				isG = true;
			}
		}
		if(isF && isG){
			myout("No");
		}else{
			myout("Yes");
		}
	}
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 20;
var union = Array(UPPER_BOUND + 10).fill(0);
union[0] = UPPER_BOUND;
for(var i = 1; i <= UPPER_BOUND + 10; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND+10) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}

for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%UPPER_BOUND);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%UPPER_BOUND)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -2;
        break;
      }
    }
  }
  if(k===843){
    if(group===-1){
      print(`A`);
    } else {
      print('B');
    }
  }
  if(group < 0) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 20;
var union = Array(UPPER_BOUND + 10).fill(0);
union[0] = UPPER_BOUND;
for(var i = 1; i <= UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}
for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%UPPER_BOUND);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%UPPER_BOUND)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -2;
        break;
      }
    }
  }
  if(k===843){
    if(group===-1){
      print(`A`);
    } else {
      print('B');
    }
  }
  if(group < 0) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 20;
var union = Array(UPPER_BOUND + 10).fill(0);
union[0] = UPPER_BOUND;
for(var i = 1; i <= UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}
for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%UPPER_BOUND);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%UPPER_BOUND)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -2;
        break;
      }
    }
  }
  if(k===844){
    if(group===-1){
      print(`A`);
    } else {
      print('B');
    }
  }
  if(group === -1) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 20;
var union = Array(UPPER_BOUND + 10).fill(0);
union[0] = UPPER_BOUND;
for(var i = 1; i <= UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}
for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%UPPER_BOUND);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%UPPER_BOUND)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -2;
        break;
      }
    }
  }
  if(group === -2) {
    print(`NO`);
    continue;
  }
  if(group === -1) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 20;
var union = Array(UPPER_BOUND + 10).fill(0);
union[0] = UPPER_BOUND;
for(var i = 1; i <= UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}
for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%UPPER_BOUND);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%UPPER_BOUND)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -1;
        break;
      }
    }
  }
  if(group === -1) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 10000;
var union = Array(UPPER_BOUND + 10).fill(0);
union[0] = UPPER_BOUND;
for(var i = 1; i <= UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}
for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%UPPER_BOUND);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%UPPER_BOUND)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -1;
        break;
      }
    }
  }
  if(group === -1) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 100;
var union = Array(UPPER_BOUND + 1).fill(0);
union[0] = UPPER_BOUND;
for(var i = 1; i <= UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}
for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%UPPER_BOUND);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%UPPER_BOUND)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -1;
        break;
      }
    }
  }
  if(group === -1) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 21;
var union = Array(UPPER_BOUND).fill(0);
union[0] = 20;
for(var i = 1; i <= UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}
for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%20);
  var lastNum = -1;
  for(var j = 0; j < n; j++) {
    if(group !== findUnion(nums[j]%20)) {
      group = -1;
      break;
    }
    if(nums[j]%5 === 0) {
      if(lastNum < 0) {
        lastNum = nums[j];
      }
      if(lastNum !== nums[j]) {
        if(lastNum % 10 === 0 && lastNum-nums[j] === 5) {
          lastNum = nums[j];
          continue;
        }
        if(nums[j] % 10 === 0 && nums[j]-lastNum === 5) {
          lastNum = nums[j];
          continue;
        }
        group = -1;
        break;
      }
    }
  }
  if(group === -1) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

var t = readline().split(' ').map((x) => parseInt(x));
var UPPER_BOUND = 21;
var union = Array(UPPER_BOUND).fill(0);
for(var i = 1; i <= UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}
for(var k = 0; k < t; k++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]%20);
  var lastNum = 1;
  for(var j = 0; j < n; j++) {
    if(nums[j]%10 === 0) {
      if(lastNum%5 === 0 && lastNum !== nums[j] - 5 && lastNum !== nums[j]) { //not 10-5
        group = -1;
        break;
      }
    }
    if(nums[j]%5 === 0) {
      if(lastNum%5 === 0 && Math.abs(lastNum - nums[j]) > 5) { //5 15
        group = -1;
        break;
      }
      lastNum = nums[j];
    }
    if(group !== findUnion(nums[j]%20)) {
      group = -1;
      break;
    }
  }
  if(group === -1) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

//preprocess disjoint set
const findUnion = (num) => {
  union[num] = union[num] === num? num : findUnion(union[num]);
  return union[num];
}

const disjoint = (num1, num2) => {
  const group1 = findUnion(num1);
  const group2 = findUnion(num2);

  union[group1] = group2;
}

const UPPER_BOUND = 200001;
var union = Array(UPPER_BOUND).fill(0);
for(var i = 1; i < UPPER_BOUND; i++) {
  var childNum = parseInt(i + (i % 10));
  if(union[i] === 0) {
    union[i] = i;
  }
  if(childNum>=UPPER_BOUND) {
      continue;
  }
  if(union[childNum] === 0) {
    union[childNum] = union[i];
  } else {
    disjoint(i, childNum);
  }
}

var t = readline().split(' ').map((x) => parseInt(x));

for(var i = 0; i < t; i++) {
  var n = readline().split(' ').map((x) => parseInt(x));
  var nums = readline().split(' ').map((x) => parseInt(x));
  var group = findUnion(nums[0]);
  for(var j = 1; j < n; j++) {
    if(group !== findUnion(nums[j])) {
      group = -1;
      break;
    }
  }
  if(group === -1) {
    print(`No`);
  } else {
    print(`Yes`);
  }
}

var t = readline();
var track = [2, 4, 8, 16, 1, 17, 19, 13];
for (var c = 0; c < t; c ++)
{
    var n = readline();
    var a = readline().split(" ").map(x => parseInt(x))
    var t = true
    if (track.includes(a[0] % 20))
    {
        for (var i = 1; i < a.length; i ++)
        {
            if (!track.includes((a[i]) % 20))
            {
                print("NO")
                i = a.length;
                t = false;
            }
        }
    }
    else if (track.includes((a[0] + 10) % 20))
    {
        for (var i = 1; i < a.length; i ++)
        {
            if (!track.includes((a[i] + 10) % 20))
            {
                print("NO")
                i = a.length;
                t = false;
            }
        }
    }
    else
    {
        var x = a[0] + a[0] % 10
        for (var i = 1; i < a.length; i ++)
        {
            if (a[i] + a[i] % 10 != x)
            {
                print("NO")
                i = a.length;
                t = false;
            }
        }
    }
    if (t){
        print("YES")
    }

}

'use strict';

function solve(n, a) {
  if (n === 1) return 'YES';
  const max = Math.max(...a);
  let has0 = false,
      has5 = false,
      nums = [];
  for (let num of a) {
    if (num % 10 === 0) {
      if (num < max) return 'NO';
      has0 = true;
    } else if (num % 5 === 0) {
      has5 = true;
    } else {
      nums.push(num);
    }
  }
  if ((has0 || has5) && nums.length) return 'NO';
  if (!nums.length) return 'YES';
  for (let i = 0; i < nums.length; i++) {
    let num = nums[i];
    while (num % 10 !== 2) {
      num += num % 10;
    }
    nums[i] = num;
  }
  let odd = 0,
      even = 0;
  for (let num of nums) {
    num = Math.floor(num / 10);
    if (num % 2 === 0) even = 1;else odd = 1;
    if (odd && even) return 'NO';
  }
  return 'YES';
}

async function main(r) {
  const rn = async () => Number(await r());
  const rns = async () => {
    return (await r()).split(' ').filter(s => s !== '').map(Number);
  };
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = await rn();
      const a = await rns();
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

function solve(n, a) {
  const max = Math.max(...a);
  let has0 = false,
      has5 = false,
      nums = [];
  for (let num of a) {
    if (num % 10 === 0) {
      has0 = true;
      if (num < max) return 'NO';
    } else if (num % 5 === 0) {
      has5 = true;
    } else {
      nums.push(num);
    }
  }
  if ((has0 || has5) && nums.length) return 'NO';
  for (let i = 0; i < nums.length; i++) {
    let num = nums[i];
    while (num % 10 !== 2) {
      num += num % 10;
    }
    nums[i] = num;
  }
  let odd = 0,
      even = 0;
  for (let num of nums) {
    num = Math.floor(num / 10);
    if (num & 1) odd = 1;else even = 1;
    if (odd && even) return 'NO';
  }
  return 'YES';
}

async function main(r) {
  const rn = async () => Number(await r());
  const rns = async () => {
    return (await r()).split(' ').filter(s => s !== '').map(Number);
  };
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = await rn();
      const a = await rns();
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    const M = {
        '0': -1,
        '1': 0,
        '2': 0,
        '3': 1,
        '4': 2,
        '5': -1,
        '6': 1,
        '7': 3,
        '8': 2,
        '9': 3,
    };

    for (let test = 0; test < N; test++) {
        const n = Number(readline());
        const arr = readline().split(' ').map(Number);

        const getType = num => {
            const digit = num % 10;
            if (digit === 0) {
                return num;
            } else if (digit === 5) {
                return num + 5;
            }
            let tens = Math.floor(num / 10);
            let tensMod = (tens + M[digit]) % 2;
            return tensMod === 0 ? 'EVEN' : 'ODD';
        }

        const mapped = arr.map(getType);
        const no = Boolean(mapped.find(el=> el !== mapped[0]));
        output(no ? 'NO' : 'YES');
    }
}

const readline = require('readline')

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

function solve(n, arr) {
    arr.sort((a, b) => b - a)
    return arr.every(x => check(x, arr[0]))
}
function check(a, b) {
    const ra = a % 10
    const rb = b % 10
    if (ra === 5 || ra === 0 || rb === 5 || rb === 0) {
        a += a % 10
        b += b % 10
        return a === b
    }
    const o = {}
    o[2] = 1
    o[4] = 2
    o[8] = 3
    o[6] = 4
    while (!o[b % 10]) {
        b += b % 10
    }
    while (a < b) {
        const r = a % 10
        if (o[r]) break
        a += r
    }
    if (a > b) return false
    const r = (b - a) % 20
// console.log(a, b, r)
    switch (a % 10) {
    case 2:
        return [0, 2, 6, 14].indexOf(r) >= 0
    case 4:
        return [0, 4, 12, 18].indexOf(r) >= 0
    case 8:
        return [0, 8, 14, 16].indexOf(r) >= 0
    case 6:
        return [0, 6, 8, 12].indexOf(r) >= 0
    }
}


There are $$$n$$$ products in the shop. The price of the $$$i$$$-th product is $$$a_i$$$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owner of the shop can change the price of some product $$$i$$$ in such a way that the difference between the old price of this product $$$a_i$$$ and the new price $$$b_i$$$ is at most $$$k$$$. In other words, the condition $$$|a_i - b_i| \le k$$$ should be satisfied ($$$|x|$$$ is the absolute value of $$$x$$$).He can change the price for each product not more than once. Note that he can leave the old prices for some products. The new price $$$b_i$$$ of each product $$$i$$$ should be positive (i.e. $$$b_i > 0$$$ should be satisfied for all $$$i$$$ from $$$1$$$ to $$$n$$$).Your task is to find out the maximum possible equal price $$$B$$$ of all productts with the restriction that for all products the condiion $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the same new price of all products) or report that it is impossible to find such price $$$B$$$.Note that the chosen price $$$B$$$ should be integer.You should answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of queries. Each query is presented by two lines. The first line of the query contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100, 1 \le k \le 10^8$$$) — the number of products and the value $$$k$$$. The second line of the query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^8$$$), where $$$a_i$$$ is the price of the $$$i$$$-th product.

Print $$$q$$$ integers, where the $$$i$$$-th integer is the answer $$$B$$$ on the $$$i$$$-th query. If it is impossible to equalize prices of all given products with restriction that for all products the condition $$$|a_i - B| \le k$$$ should be satisfied (where $$$a_i$$$ is the old price of the product and $$$B$$$ is the new equal price of all products), print -1. Otherwise print the maximum possible equal price of all products.

NoteIn the first example query you can choose the price $$$B=2$$$. It is easy to see that the difference between each old price and each new price $$$B=2$$$ is no more than $$$1$$$.In the second example query you can choose the price $$$B=6$$$ and then all the differences between old and new price $$$B=6$$$ will be no more than $$$2$$$.In the third example query you cannot choose any suitable price $$$B$$$. For any value $$$B$$$ at least one condition out of two will be violated: $$$|1-B| \le 2$$$, $$$|6-B| \le 2$$$.In the fourth example query all values $$$B$$$ between $$$1$$$ and $$$7$$$ are valid. But the maximum is $$$7$$$, so it's the answer.

let input = "";
const { EOL } = require("os");
process.stdin.on("data", i => (input += i));

process.stdin.on("end", async () => {
  console.log(func(input));
});

const func = a => {
  let result = "";
  const [q, ...queries] = a.split(EOL);
  for (let i = 0; i < q; i++) {
    const [n, maxPriceDiff] = queries.shift().split(" ").map(a => parseInt(a));
    const products = queries
      .shift()
      .split(" ")
      .map(a => parseInt(a))
      .sort((a, b) => a - b);
    result +=
      (Math.abs(products[products.length - 1] - products[0]) <= maxPriceDiff * 2
        ? products[0] + maxPriceDiff
        : -1) + EOL;
  }
  return result;
};

module.exports = func;

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

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

  if (c % 2 === 1) {
    [n, k] = d.split(' ').map(Number);
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  const min = Math.min(...arr);
  const max = Math.max(...arr);
  let ans = min + k;

  if (min +  k < max - k) {
    ans = - 1;
  }

  console.log(ans);

  c++;
});

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

    var q = read.number();
    var res = '';
    while (q) {
        q--;

        var line = read.arrNumber(' ');
        var n = line[0];
        var k = line[1];
        var a = read.arrNumber(' ');

        var max = a[0], min = a[0];
        for (var i = 0; i < n; i++) {
            if (max < a[i]) {
                max = a[i];
            }
            if (min > a[i]) {
                min = a[i];
            }
        }

        if ((max - min) > 2 * k) {
            res += '-1\n';
        } else {
            res += (min + k) + '\n';
        }

    }
    print(res);

}());

var qs = readline().split(' ').map(Number);

for (var i = 0; i < qs; i++) {
  var _ = readline().split(' ').map(Number);
  var n = _[0];
  var k = _[1];

  var goods = readline().split(' ').map(Number);

  var max = maxEl(goods);
  var min = minEl(goods);

  if (min + k >= max - k) {
    print(min + k);
  } else {
    print(-1);
  }
}

function minEl(arr) {
  var min = arr[0];
  for (var i = 1; i < arr.length; i++) {
    if (arr[i] < min) {
      min = arr[i];
    }
  }

  return min;
}

function maxEl(arr) {
  var max = arr[0];
  for (var i = 1; i < arr.length; i++) {
    if (arr[i] > max) {
      max = arr[i];
    }
  }

  return max;
}

"use strict";

var q = +readline()

while (q--) {
    var input = readline().split(' ').map(value => +value);
    var n = input[0];
    var k = input[1];
    var A = readline().split(' ').map(value => +value);

    A.sort(function(a, b) {return a - b;});
    var result = A[0] + k;
    if (result < (A[n-1] - k)) {
        write('-1\n');
    } else {
        write(result + '\n');
    }
}

var qs = readline().split(' ').map(Number);

for (var i = 0; i < qs; i++) {
  var _ = readline().split(' ').map(Number);
  var n = _[0];
  var k = _[1];

  var goods = readline().split(' ').map(Number);

  var sum = goods.reduce(function(prev, cur) {
    return prev + cur;
  });

  var avg = Math.ceil(sum / n);

  var max = maxEl(goods);
  var min = minEl(goods);

  if (avg - min > k || max - avg > k) {
    print(-1);
  } else if (avg - min < k)  {
    print(min + k);
  } else {
    print(avg);
  }
}

function minEl(arr) {
  var min = arr[0];
  for (var i = 1; i < arr.length; i++) {
    if (arr[i] < min) {
      min = arr[i];
    }
  }

  return min;
}

function maxEl(arr) {
  var max = arr[0];
  for (var i = 1; i < arr.length; i++) {
    if (arr[i] > max) {
      max = arr[i];
    }
  }

  return max;
}

"use strict";

var q = +readline()

while (q--) {
    var input = readline().split(' ').map(value => +value);
    var n = input[0];
    var k = input[1];
    var A = readline().split(' ').map(value => +value);

    A.sort();
    var result = A[0] + k;
    if (result < (A[n-1] - k)) {
        write('-1\n');
    } else {
        write(result + '\n');
    }
}


There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?Formally, we assume that two words denote the same name, if using the replacements "u"  "oo" and "h"  "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.For example, the following pairs of words denote the same name:  "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper"  "kuuper" and "kuooper"  "kuuper".  "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun"  "khoon" and "kkkhoon"  "kkhoon"  "khoon". For a given list of words, find the minimal number of groups where the words in each group denote the same name.

The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.

Print the minimal number of groups where the words in each group denote the same name.

10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon

9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi

NoteThere are four groups of words in the first example. Words in each group denote same name:  "mihail", "mikhail"  "oolyana", "ulyana"  "kooooper", "koouper"  "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name:  "hariton", "kkkhariton", "khariton"  "hkariton"  "buoi", "boooi", "boui"  "bui"  "boi" In the third example the words are equal, so they denote the same name.

function kek(s)
{
    for (var i=0;i<=20;i++)
    {
        s=s.replace("u","oo")
        s=s.replace("kh","h");
    }
    return s;
}

var n=+readline()
var x=[]
while(n--)
{
    x.push(kek(readline()))
}
x.sort()
var res=1
for (var i=1;i<x.length;i++)
{
    if (x[i]!=x[i-1]){res++;}
}
print(res)//

function kek(s)
{
    s=s.replace("u","oo")
    for (var i=0;i<=20;i++)
    {
        s=s.replace("kh","h");
    }
    return s;
}

var n=+readline()
var x=[]
while(n--)
{
    x.push(kek(readline()))
}
x.sort()
var res=1
for (var i=1;i<x.length;i++)
{
    if (x[i]!=x[i-1]){res++;}
}
print(res)


A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient X — the coefficient of income growth during one year. This coefficient should satisfy the equation:A·Xn = B.Surely, the king is not going to do this job by himself, and demands you to find such number X.It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient X must be integers. The number X may be zero or negative.

The input contains three integers A, B, n (|A|, |B| ≤ 1000, 1 ≤ n ≤ 10).

Output the required integer coefficient X, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.

const readline = require('readline');

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

rl.on('line', function (input) {
    var myArr = input.split(' ').map(item => { return parseFloat(item); });
    //****************************************** DO IT HERE*/
    var A = myArr[0], B = myArr[1];
    var N = parseInt(myArr[2]);
    var helper = 0;
    if(A==0 && B==0) helper = 0;
    else if (A==0 && B!=0) helper = -2;
    else helper = B/A;

    var needMinus = false;
    if(helper<0 && N%2)
    {
        needMinus = true;
        helper = -helper;
    }
    var ans = NthRoot(helper,N);
    if(ans>0)
    {
        ans+=0.0001;
        ans = Math.trunc(ans*1000);
        ans /=1000;
    }

    var temp = Math.trunc(ans);
    if(ans == temp)
        console.log(needMinus? "-" + ans : ans.toString());
    else
        console.log("No solution");

    rl.close();
    /*************************************** */

})

function NthRoot(Base, n) {
    return Math.pow(Base, 1.0 / n);
}

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))

let bo = lll[0]
let bn = lll[1]
let n = lll[2]

let res = 'No solution'
;(function () {
  for (let i = -1000; i <= 1000; i++) {
    if (bo * Math.pow(i, n) == bn) return res = i
  }
})()

print(res)

const readline = require('readline');

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

rl.on('line', function (input) {
    var myArr = input.split(' ').map(item => { return parseFloat(item); });
    //****************************************** DO IT HERE*/
    var A = myArr[0], B = myArr[1];
    var N = parseInt(myArr[2]);
    var helper = 0;
    if(A==0 && B==0) helper = 0;
    else if (A==0 && B!=0) helper = -2;
    else helper = B/A;

    var needMinus = false;
    if(helper<0 && N%2)
    {
        needMinus = true;
        helper = -helper;
    }
    var ans = NthRoot(helper,N);
    if(ans>0)
    {
        ans+=0.0001;
        ans = Math.trunc(ans*1000);
        ans /=1000;
    }

    var temp = Math.trunc(ans);
    if(ans == temp)
        console.log(needMinus? "-" + ans : ans.toString());
    else
        console.log("No Solution");

    rl.close();
    /*************************************** */

})

function NthRoot(Base, n) {
    return Math.pow(Base, 1.0 / n);
}