let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  const [len, t] = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  arr.sort((a, b) => a - b);
  let result = 0;
  for (let i = 0; i < t; i++) {
    if (arr[i] < 0) result += Math.abs(arr[i]);
  }

  console.log(result);
}

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

rl.on('line', (d) => {
  if (c === 0) {
    [n, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  let sum = 0;

  for (let i = 0; i < m; i++) {
    if (arr[i] < 0) {
      sum += Math.abs(arr[i]);
    }
  }

  console.log(sum);

  c++;
});

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
        process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });
    });
}

async function main(){
    data = (await input()).split("\r\n");
    var temp = data[0].split(" ");
    var n = Number(temp[0]),
        m = Number(temp[1]);

    temp = data[1].split(" ");
    var arr = [];
    for(i = 0; i < n; i++){
        arr.push(Number(temp[i]));
    }
    arr.sort(function(a, b){return a - b});
    var ans = 0;
    for(i = 0; i < m && arr[i] < 0; i++){
      ans += arr[i] * -1;
    }
    console.log(ans);

}
main();

var l=readline().split(' ');
var n=+l[0];
var m=+l[1];
var a=readline().split(' ').map(function(v){return +v;});
a.sort(function(a, b){
	return a-b;
});

var ans=0;
for(var i=0; i<m; i++){
	if(a[i]<0){
		ans+=- a[i] ;
	}
}
print(ans);

var a = readline().split(' ').map(e=>Number(e));
var b = readline().split(' ').map(e=>Number(e)).sort((a,b)=>a-b).filter(e=>{return(e < 0)}).slice(0,a[1]);

if (b.length === 0){
	print(0);
} else {
	print(-(b.reduce((prev,next)=>prev+next)));
}

var n = readline().split(' ').map(function(x) {return parseInt(x);});
var a = readline().split(' ').map(function(x) {return parseInt(x);}).sort(function(a, b){return a - b;});
var res = 0, carried = 0;

for(var i = 0; i < n[0]; ++i)
	if(a[i] >= 0 || carried >= n[1])
		break;
	else
	{
		res -= a[i];
		++carried;
	}
write(res);

var t = readline().split(' ').map(cur => Number(cur));
var inp = readline().split(' ').map(cur => Number(cur)).sort((a,b) => {
return a-b;
});
var sum = 0;
for (var i = 0; i < t[1]; i++){
    if(inp[i] <= 0)
    sum-= inp[i];
}
print(sum);

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

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

var dp = {};

function fibonacci(n) {
	if (n === 0) return 0;
	if (n === 1) return 1;

	if (dp[n] !== undefined) return dp[n];
	let result = fibonacci(n - 1) + fibonacci(n - 2);
	return (dp[n] = result);
}

function main() {
	let [n, m] = readLine()
		.split(' ')
		.map(x => x >> 0);

	let p = readLine()
		.split(' ')
		.map(x => x >> 0);

	p.sort((a, b) => a - b);
	let s = 0;
	for (let i = 0; i < m; ++i) if (p[i] < 0) s += p[i];

	s = s < 0 ? s * -1 : s;
	console.log(s);
}

;(function () {
	print(function (n, m) {
		var s = readline().split(' ').map(Number).filter(function (e) { return e < 0; }).sort(function (a, b) { return a - b; }),
			l = 0, k = 0;

		for (var i = 0, _i = Math.min(m, s.length); i < _i; i++) {
			l += -s[i];
		}

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

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}
function main() {
    let [n, m] = readLine().split(' ').map(Number);
    let prices = readLine().split(' ').map(Number);
    prices.sort((a, b) => {
        return a - b;
    });
    let final = 0;
    for (let i = 0; i < m; i++) {
        if (Math.sign(prices[i]) === -1) {
            final += Math.abs(prices[i]);
        }
    }
    console.log(final);
}

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var itemNum = integers[0], capacity = integers[1];

	var weights = tokenizeIntegers(readline());
	weights.sort(function(a, b) {
		return a-b;
	});

	var total = 0;
	for (var i = 0; i < capacity; ++i) {
		if (weights[i] >= 0) {
			break;
		}
		total -= weights[i];
	}
	print(total);
}

main();

	//this code is written by ashraf

var n = readline().split(' ');
var ll = readline().split(" ").sort((a,b)=>a-b);
var llsort = [];
for(var i=0;i<ll.length;i++){if((+ll[i])<=0){llsort.push(ll[i])}}

if(llsort.length==0){print(0)}else{

var ashraf =0
if(llsort.length<n[1]) {n[1] =llsort.length}

for(var x = 0;x<n[1];x++){
 ashraf =ashraf+parseInt(llsort[x]) ;

}
ashraf = ashraf *-1
print(ashraf)
}

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let N = lll[0]
let M = lll[1]
let res = readline().split(' ').map(v => parseInt(v))
  .filter(v => v < 0)
  .sort((a, b) => a - b)
  .slice(0, M)
  .reduce((r, v) => r + v, 0)

print(-res)

  var inp = readline().split(' ').map(v => parseInt(v));
  var n = inp[0];
  var max = inp[1];
  var sorted = readline().split(' ')
			 .map(e=>Number(e))
			 .filter(x=> x < 0)
			 .sort(function(a,b){return a - b});
  var sum = 0;

  for (var i=0; i<sorted.length;i++){
    if (i==max){
        break;
    }
    if(sorted[i] < 0){
      sum = sorted[i] + sum;
    }

  }
  print(-1*sum);

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.trim().split(' ').map(x => +x)
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

var l=readline().split(' ');
var n=+l[0];
var m=+l[1];
var a=readline().split(' ').map(function(v){return +v;});
a.sort(function(a, b){
	return a-b;
});

var ans=0;
for(var i=0; i<m; i++){
	ans+=0-a[i];
}
print(ans);

var n = readline().split(' ').map(function(x) {return parseInt(x);});
var a = readline().split(' ').map(function(x) {return parseInt(x);}).sort(function(a, b){return a - b;});
var res = 0, carried = 0;

for(var i = n[0] - 1; i >= 0; --i)
	if(a[i] >= 0 || carried >= n[1])
		break;
	else
	{
		res -= a[i];
		++carried;
	}
write(res);

var n = readline().split(' ').map(function(x) {return parseInt(x);});
var a = readline().split(' ').map(function(x) {return parseInt(x);}).sort();
var res = 0, carried = 0;

for(var i = n[0] - 1; i >= 0; --i)
	if(a[i] >= 0 || carried >= n[1])
		break;
	else
	{
		res -= a[i];
		++carried;
	}
write(res);

var n = readline().split(' ').map(function(x) {return parseInt(x);});
var a = readline().split(' ').map(function(x) {return parseInt(x);});
a.sort();
var res = 0,
	carried = 0;
for(var i = 0; i < n[0]; ++i)
	if(a[i] >= 0 || carried >= n[1])
		break;
	else
	{
		res -= a[i];
		++carried;
	}
write(res);

;(function () {
	print(function (n, m) {
		var s = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
			l = 0, k = 0;

		for (var i = 0; i < n && k < m; i++) {
			if (s[i] <= l) {
				l -= s[i];
				k++
			} else {
				break;
			}
		}

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

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var itemNum = integers[0], capacity = integers[1];

	var weights = tokenizeIntegers(readline());
	weights.sort(function(a, b) {
		return a-b;
	});

	var total = 0;
	for (var i = 0; i < capacity; ++i) {
		total -= weights[i];
	}
	print(total);
}

main();

  var inp = readline().split(' ').map(v => parseInt(v));
  var n = inp[0];
  var max = inp[1];
  var sorted = readline().split(' ')
			 .filter(x=> x < 0)
			 .sort(function(a,b){return a - b});
  var sum = 0;

  for (var i=0; i<sorted.length;i++){
    if (i==max){
        break;
    }
    if(sorted[i] < 0){
      sum = sorted[i] + sum;
    }

  }
  print(-1*sum);

  var inp = readline().split(' ').map(v => parseInt(v));
  var n = inp[0];
  var max = inp[1];
  var sorted = readline().split(' ').map(e=>Number(e)).sort();
  var sum = 0;

  for (var i=0; i<sorted.length;i++){
    if(sorted[i] < 0){
      sum = sorted[i] + sum;
    }
    if (i==max){
        break;
    }
  }
  print(-1*sum);

  var inp = readline().split(' ').map(v => parseInt(v));
  var n = inp[0];
  var max = inp[1];
  var sorted = readline().split(' ').map(e=>Number(e)).sort();
  var sum = 0;

  for (var i=0; i<sorted.length;i++){
    if (i==max){
        break;
    }
    if(sorted[i] < 0){
      sum = sorted[i] + sum;
    }

  }
  print(-1*sum);

var a = readline().split(' ').map(e=>Number(e));
var b = readline().split(' ').map(e=>Number(e)).sort((a,b)=>a-b).filter(e=>{return(e < 0)}).slice(0,a[1]);

if (b.length === 0){
	print(0);
} else {
	print(b.reduce((prev,next)=>prev+next));
}

'use strict';

var a = readline().split(' ');
var b = readline().split(' ').map(function (e) {
	return Number(e);
}).filter(function (e) {
	return e < 0;
});

if (b.length === 0) {
	print(0);
} else {
	var p = new Promise(function (resolve, reject) {
		var what = 0;
		for (var i = 0; i < a[1]; i++) {
			var max = b.reduce(function (prev, next) {
				return Math.max(prev, next);
			});
			b.pop(b.indexOf(max));
			what += max;
		}
		resolve(what);
	});p.then(function (data) {
		print(what);
	});
}

var a = readline().split(' ');
var b = readline().split(' ').filter(e=>Number(e)<0).map(e=>Number(e)).sort().slice(0,a[0]).reduce((prev,next)=>prev+next);
print(b);

'use strict';

var a = readline().split(' ');
var b = readline().split(' ').map(function (e) {
	return Number(e);
}).filter(function (e) {
	return e < 0;
});

if (b.length === 0) {
	print(0);
} else {
	var p = new Promise(function (resolve, reject) {
		var what = 0;
		for (var i = 0; i < a[1]; i++) {
			var max = b.reduce(function (prev, next) {
				return Math.max(prev, next);
			});
			b.pop(b.indexOf(max));
			what += max;
		}
		resolve(what);
	});p.then(function (data) {
		print(data);
	});
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).filter(e=>e<0);

if (b.length === 0){
	print(0);
} else {
	var p = new Promise((resolve,reject)=>{
		var what = 0;
		for(var i = 0; i < a[1]; i++){
			var max = b.reduce((prev,next)=>Math.max(prev,next));
			b.pop(b.indexOf(max));
			what+=max;
		}
		resolve(what);
	}); p.then(data=>{
		print(what);
	})
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[1]);
if (b.length === 0){
	print(0);
} else {
	print(-(b.reduce((prev,next)=>prev+next)));
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[0]);
if (b.length === 0){
	print(0);
} else {
	print(-(b.reduce((prev,next)=>prev+next)));
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).sort().reverse().filter(e=>Number(e)<0).slice(0,a[1]);
if (b.length === 0){
	print(0);
} else {
	print(-(b.reduce((prev,next)=>prev+next)));
}

var a = readline().split(' ');
var b = readline().split(' ').map(e=>Number(e)).sort().filter(e=>Number(e)<0).slice(0,a[0]);
if (b === []){
	print(0);
} else {
	print(b.reduce((prev,next)=>prev+next));
}

var t = readline().split(' ').map(cur => Number(cur));
var inp = readline().split(' ').map(cur => Number(cur)).sort((a,b) => {
return a-b;
});
var sum = 0;
for (var i = 0; i < t[1]; i++){
    sum-= inp[i];
}
print(sum);
//

//this code is written by ashraf

var n = readline().split(' ');
var ll = readline().split(" ").sort((a,b)=>a-b);
var llsort = [];
for(var i=0;i<ll.length;i++){if((+ll[i])<=0){llsort.push(ll[i])}}

if(llsort.length==0){print(0)};

var ashraf =0
if(llsort.length<n[1]) {n[1] =llsort.length}
for(var x = 0;x<n[1];x++){
 ashraf =ashraf+parseInt(llsort[x]) ;

}
ashraf = ashraf *-1
print(ashraf)

//this code is written by ashraf

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

var ashraf =0

for(var x = 0;x<n[1];x++){
 ashraf =ashraf+parseInt(ll[x]) ;

}
if(ashraf<0){ashraf=ashraf*-1}else{print("0")}
print(ashraf)

//this code is written by ashraf

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

var ashraf =0

for(var x = 0;x<n[1];x++){
 ashraf =ashraf+parseInt(ll[x]) ;

}
ashraf = ashraf*-1 ;

print(ashraf)

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.split(' ').map(x => {
            if (x) {
                return +x
            }
        })
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.trim().split(' ').map(x => +x)
        console.log(prices)
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.trim().split(' ').map(x => +x)
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.split(' ').map(x => +x);
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.split(' ').map(x => +x);
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += -price
            } else {
                result -= price
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n, m, c = 0;
rl.on('line', input => {
    if ( n && m && c < 2) {
        let prices = input.trim().split(' ').map(x => +x)
        function swap(items, a, b) {
            let k = items[a];
            items[a] = items[b];
            items[b] = k;
        }
        function partition(items, left, right) {
            var pivot = items[Math.floor((right + left) / 2)],
                i = left,
                j = right;
            while (i <= j) {
                while (items[i] < pivot && i <= j) {
                    i++;
                }
                while (items[j] > pivot) {
                    j--;
                }
                if (i <= j && i <= j) {
                    swap(items, i, j);
                    i++;
                    j--;
                }
            }
            return i;
        }
        function sorting (items, left, right) {
            let index;

            if (items.length > 1) {
                index = partition(items, left, right);
                if ( left < index - 1){
                    sorting(items, left, index - 1);
                }
                if (right > index - 1) {
                    sorting(items, index, right)
                }
            }
            return items
        }
        let semiresult = sorting(prices, 0, prices.length -1);
        semiresult = semiresult.slice(0, m - 1);
        let result = 0;
        semiresult.map(price => {
            if (price < 0) {
                result += price * -1
            }
        })
        c++
        console.log(result)
        rl.close()
    } else {
        [n, m] = input.split(' ').map(x => +x);
    }
})

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

rl.on('line', (d) => {
  if (c === 0) {
    [n, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  let sum = 0;

  for (let i = 0; i < m; i++) {
    sum += Math.abs(arr[i]);
  }

  console.log(sum);

  c++;
});

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
        process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });
    });
}

async function main(){
    data = (await input()).split("\r\n");
    var temp = data[0].split(" ");
    var n = Number(temp[0]),
        m = Number(temp[1]);

    temp = data[1].split(" ");
    var arr = [];
    for(i = 0; i < n; i++){
        arr[i] = Number(temp[i]);
    }
    arr = arr.sort();
    var ans = 0;
    for(i = 0; i < n; i++){
        if(arr[i] < 0 && i < m) ans += arr[i] * -1;
    }
    console.log(ans);

}
main();

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

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
       readline.question('', (data) => {
           resolve(data);
       });
    });
}

async function main(){

    const n = Number(await input());
    const m = Number(await input());
    var arr = []
    for(i = 0; i < n; i++) arr[i] = Number(await input());
    arr = arr.sort();
    var ans = 0;
    for(i = 0; i < n; i++){
        if(arr[i] < 0) ans += arr[i] * -1;
    }
    console.log(ans);

    // to end the terminal
    readline.close();
}
main();

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

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
       readline.question('', (data) => {
           resolve(data);
       });
    });
}

async function main(){

    var temp = (await input()).split(" ");
    var n = Number(temp[0]);
    var m = Number(temp[1]);
    temp = (await input()).split(" ");
    var arr = [];
    for(i = 0; i < n; i++){
        arr[i] = Number(temp[i]);
    }
    arr = arr.sort();
    var ans = 0;
    for(i = 0; i < n; i++){
        if(arr[i] < 0) ans += arr[i] * -1;
    }
    console.log(ans);

    // to end the terminal
    readline.close();
}
main();

// input function
// to take input use   in = await input()
function input(){
    return new Promise ( (resolve , error) => {
        process.stdin.on('data', (chunk) => { resolve(chunk.toString()) });
    });
}

async function main(){
    data = (await input()).split("\r\n");
    var temp = data[0].split(" ");
    var n = Number(temp[0]),
        m = Number(temp[1]);

    temp = data[1].split(" ");
    var arr = [];
    for(i = 0; i < n; i++){
        arr.push(Number(temp[i]));
    }
    arr = arr.sort();
    var ans = 0;
    for(i = 0; i < n; i++){
        if(arr[i] < 0 && i < m) ans += arr[i] * -1;
    }
    console.log(ans);

}
main();

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

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

var dp = {};

function fibonacci(n) {
	if (n === 0) return 0;
	if (n === 1) return 1;

	if (dp[n] !== undefined) return dp[n];
	let result = fibonacci(n - 1) + fibonacci(n - 2);
	return (dp[n] = result);
}

function main() {
	let [n, m] = readLine()
		.split(' ')
		.map(x => x >> 0);

	let p = readLine()
		.split(' ')
		.map(x => x >> 0);

	p.sort((a, b) => a - b);
	let s = 0;
	for (let i = 0; i < m; ++i) {
		s += p[i];
	}
	s = s < 0 ? s * -1 : s;
	console.log(s);
}

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

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

var dp = {};

function fibonacci(n) {
	if (n === 0) return 0;
	if (n === 1) return 1;

	if (dp[n] !== undefined) return dp[n];
	let result = fibonacci(n - 1) + fibonacci(n - 2);
	return (dp[n] = result);
}

function main() {
	let [n, m] = readLine()
		.split(' ')
		.map(x => x >> 0);

	let p = readLine()
		.split(' ')
		.map(x => x >> 0);

	p.sort((a, b) => a - b);
	let s = 0;
	for (let i = 0; i < m; ++i) {
		s += p[i];
	}
	console.log(s);
}


var t = parseInt(readline());

while(t--){
  var n = parseInt(readline());
  var ones = Math.floor(n/2);

  var result = "";
  if (n % 2 == 1)
  {
    result += "7";
    ones--;
  }

  while(ones--)
  {
    result += "1";
  }

  print(result);
}

'use strict'

const problem = (n) => (n%2 ? '7' : '1') + '1'.repeat((n>>1) - 1);

let t = +readline()
while(t--) print(problem(+readline()))

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").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;}}
function Main() {
    var t = myconv(next(),1);
    var output = [];
    for(var i = 0; i < t; i++){
        var n = myconv(next(),1);
        if(n == 2){
            output.push("1");
        }else if(n == 3){
            output.push("7");
        }else{
            if(n % 2 == 0){
                output.push(new Array(n/2).fill("1").join(""));
            }else{
                output.push("7" + new Array((n-3)/2).fill("1").join(""));
            }
        }
    }
    myout(myconv(output,9));
}

'use strict';

function a(n) {
  if (n % 2 === 1) {
    return '7' + '1'.repeat((n-3)/2);
  }
  return '1'.repeat(n/2);
}

function main() {
  const t = Number(readline());
  for(let i = 0; i < t; i++) {
    const n = Number(readline());
    print(a(n));
  }
}

main();

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

let c = 0;
let ans = "";
const obj = {
  0: 6,
  1: 2,
  2: 5,
  3: 5,
  4: 4,
  5: 5,
  6: 6,
  7: 3,
  8: 7,
  9: 6,
};

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

  let n = +d;
  let val = "";

  if (n % 2 === 0) {
    val += "1".repeat(n / 2);
  } else {
    val += "7";
    n -= 3;
    val += "1".repeat(n / 2);
  }

  ans += `${val}\n`;

  c++;
});

rl.on("close", () => {
  console.log(ans);
});

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

let c = 0;
let ans = "";

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

  let n = +d;
  let val = "";

  if (n % 2) {
    val += "7";
    n -= 3;
  }

  val += "1".repeat(n / 2);
  ans += `${val}\n`;

  c++;
});

rl.on("close", () => {
  console.log(ans);
});

let i = ''
var segments = {
    1: 2,
    7: 3,
}
var segmentHistory = new Map();
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    for (var index = 1; index < lines.length; index++) {
        segmentHistory = new Map();
        console.log(largestNum(lines[index]))
    }
})

function largestNum(n) {
    var arr = []
    if (n % 2 === 1) {
        arr.length = (n-3)/2
        arr.fill('1')
        return '7' + arr.join('')
    }
    else {
        arr.length = n/2
        arr.fill('1')
        return arr.join('')
    }
}

const calc = (d, x) => Math.ceil( d / (x + 1) + x)

const processData = (lines) => {
  const num = +lines[0]

  for (let j=1; j<=num; j++){
    let n = +lines[j]
    let result = ''
    if (n%2 === 1) {
      result = '7'
      n -= 2
    }
    for (let r = n; r > 1; r -= 2) {
      result += '1'
    }
    console.log(result)
  }
}

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

const calc = (d, x) => Math.ceil( d / (x + 1) + x)

const processData = (lines) => {
  const num = +lines[0]

  for (let j=1; j<=num; j++){
    const n = +lines[j]
    let result = ''
    for (let r = n; r > 1; r -= 2) {
      if (n == 3) {
        result += '7'
      } else {
        result += '1'
      }
    }
    console.log(result)
  }
}

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

T=+readline()
for (i=0;i<T;i++)
{
    n=+readline()
    if (n%2==0)
    {
        a=[]
        for (x=0;x<n;x+=2)
            a.push(1)
        print(a.join())
    } else {
        a=[]
        --n
        for (x=0;x<n;x+=2)
            a.push(1)
        a[a.length-1]=7
        print(a.join(''))
    }
}

T=+readline()
for (i=0;i<T;i++)
{
    n=+readline()
    if (n%2==0)
    {
        a=[]
        for (x=0;x<n;x+=2)
            a.push(1)
        print(a.join())
    } else {
        a=[]
        --n
        for (x=0;x<n;x+=2)
            a.push(1)
        a[a.length-1]=7
        print(a.join())
    }
}

T=+readline()
for (i=0;i<T;i++)
{
    n=+readline()
    if (n%2==0)
    {
        a=[]
        for (x=0;x<n;x+=2)
            a.push(1)
        print(a.join(''))
    } else {
        a=[]
        --n
        for (x=0;x<n;x+=2)
            a.push(1)
        a[a.length-1]=7
        print(a.join(''))
    }
}

'use strict'

const problem = (n) => '1'.repeat((n>>1) - 1) + (n%2 ? '7' : '1')

let t = +readline()
while(t--) print(problem(+readline()))

let i = ''
var segments = {
    1: 2,
    7: 3,
}
var segmentHistory = new Map();
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    for (var index = 1; index < lines.length; index++) {
        segmentHistory = new Map();
        console.log(largestNum(lines[index]))
        console.log(segmentHistory)
    }
})

function largestNum(n) {
    if (segmentHistory.has(n)) return segmentHistory.get(n)
    if (n <= 1) return ''
    var largest = -1
    for (const num in segments) {
        var cur = ''
        if (segments[num] <= n) {
            cur = num + largestNum(n-segments[num])
        }
        largest = Math.max(largest, +cur)
    }
    segmentHistory.set(n, largest)
    return largest
}


let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if(lines[j] % 7 === 0){
           c = lines[j]
                  console.log(c)

       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
               console.log(c)

       }
   }
});

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var y = readline();
            var n = parseInt(y);
            if(n % 7 == 0) {
                console.log(n);
                continue;
            }
            n -= n%10;
            while(n%7 !== 0) n++
            console.log(n);
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var a = k[k.length - 1];
        var b = lines[j] - a + 1;
        if(lines[j] % 7 === 0){
            b = lines[j] ;
            console.log(b);
        }else{
            while(b % 7 !== 0){
                b++;
                if(b % 7 === 0){
                    break;
                }
            }
            console.log(b);
            }
        }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input =parseInt(readline());
    if(input < 10) console.log(7)
    else if(input%7 == 0) console.log(input)
    else{
        if(input%7 <= input%10){
            console.log(input-input%7);
        }else{
            console.log(input+(7-input%7));
        }
    }
 }
}

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
function differentDigits(a, b) {
  a = "" + a;
  b = "" + b;
  if (a.length !== b.length) {
    return false;
  }
  let count = 0;
  for (let i = 0; i < a.length; i++) {
    if (a[i] !== b[i]) {
      count++;
    }
  }
  return count;
}
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0].trim());
  let i = 1;
  let dividends = [];
  for (let i = 0; i <= 999; i += 7) {
    dividends.push(i);
  }
  while (t--) {
    let n = parseInt(lines[i++].trim());
    let min = 5;
    let result;
    for (let i = 0; i < dividends.length; i++) {
      let x = differentDigits(n, dividends[i]);
      if (x === false) {
        continue;
      }
      if (x < min) {
        min = x;
        result = dividends[i];
      }
    }
    console.log(result);
  }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(s => s.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();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);

        let rem = n % 7;
        if (rem === 0) {
            output(n);
            continue;
        }

        let zeroLast = Math.floor(n / 10) * 10;

        for (let i = 0; i < 10; i++) {
            if ((zeroLast + i) % 7 === 0) {
                output(zeroLast + i);
                break;
            }
        }
    }
}

//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();
		if(N % 7 == 0){
			myout(N);
			continue;
		}
		var S = [];
		while(N > 0){
			S.unshift(N % 10);
			N = Math.floor(N / 10);
		}
		var max = 4;
		var output = 0;
		for(var i = 0; i <= 999; i += 7){
			var L = [];
			var V = i;
			while(V > 0){
				L.unshift(V % 10);
				V = Math.floor(V / 10);
			}
			if(L.length != S.length){
				continue;
			}
			var c = 0;
			for(var j = 0; j < 3; j++){
				if(L[j] != S[j]){
					c++;
				}
			}
			if(max > c){
				max = c;
				output = i;
			}
		}
		myout(output);
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    let num = parseInt(readLine());
    if (num % 7 == 0) return num;
    let boundary1 = parseInt(num / 10) * 10;
    let boundary2 = parseInt(num / 10) * 10 + 9;
    let rem = num % 7;
    if ((num - rem) >= boundary1 && (num - rem) <= boundary2)
        return num - rem;
    return num + 7 - rem;
}

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++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    if (n % 7) {
        if (n < 10) return 7
        const r = n % 10
        const add = 7 - n % 7
        if (r + add < 10) {
            return n + add
        } else {
            return n - n % 7
        }
    } else {
        return n
    }
}

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let x = nl.num();

		if (x % 7 == 0) {
			ans.push(x);
		} else if (x % 10 - x % 7 > 0) {
			ans.push(x - x % 7);
		} else {
			ans.push(x + (7 -  x % 7));
		}
	}
	console.log(ans.join('\n'));
};

process.stdin.on('end', sol);

'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 main() {
    const t = readline();
    let input = Number(readline());
    let nums = [];
    nums.push(input);

    for(let i = 2; i <= t; i++ ) {
        input = Number(readline());
        nums.push(input)
    }

    for(let num of nums) {
          if (num % 7 === 0) {
               console.log(num)
               continue;
          }

          let arrFromNum = String(num).split('');
          for (let i = 0; i < arrFromNum.length; i++) {
               let curArr = arrFromNum.concat();
               for (let j = 1; j <= 9; j++) {
                    curArr[i] = j;
                    let newNum = Number(curArr.join(''));
                    if (newNum % 7 === 0) {
                         console.log(newNum);
                         break;
                    }
               }
               break;
          }
     }
}

var t = +readline();

while(t--) {
   var n = +readline();
   if (n % 7 === 0) {
        print(n)
   } else {
        var nNew = n - n%10;
        var remainder = nNew % 7;
        print(remainder ? nNew + 7 - remainder : nNew);
   }
}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var nNew = n - n%10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var notAtZero = n%10;
  var nNew = notAtZero ? Math.floor(n/10)*10 : n;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  //var nNew = Math.floor(n/10)*10;
  var nNew = n - n%10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var nNew = Math.floor(n/10)*10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = parseInt(readline());
   if (n % 7 === 0) {
       print(n)
   } else {
  var nNew = Math.floor(n/10)*10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

function singleTest(n) {
  if (n % 7 === 0) return n;
  var nNew = Math.floor(n/10)*10;
  var remainder = nNew % 7;
  return remainder ? nNew + 7 - remainder : nNew;
}

for (var i = 0; i < t; i++) {
   var number = parseInt(readline());
   print(singleTest(number));
}

var t = parseInt(readline());
for (var i = 0; i < t; i++) {
  var n = parseInt(readline());
  if (n % 7 === 0) {
    print(n);
  } else {
    n = Math.floor(n / 10) * 10;
    for (var j = 0; j < 10; j++) {
      if ((n + j) % 7 === 0) {
        print(n + j);
        break;
      }
    }
  }
}

// var { readline, print, testOutput, console } = require("@ip-algorithmics/codeforces-io");

var t = parseInt(readline());
for (var i = 0; i < t; i++) {
  var n = parseInt(readline());
  if (n % 7 === 0) {
    print(n);
  } else {
    n = Math.floor(n / 10) * 10;
    for (var j = 0; j < 10; j++) {
      if ((n + j) % 7 === 0) {
        print(n + j);
        break;
      }
    }
  }
}

// testOutput();

var n = parseInt(readline())

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff && minAns.length === num.toString().length) {
      print(minAns);
    }
    else {
      print(maxAns);
    }

  }
}

var lines = parseInt(readline());

for (var i = 0; i < lines; i++) {
  var number = parseInt(readline());
  var remainder = number % 7;
  if (remainder <= number % 10) print(number - remainder);
  else print(number + (7 - remainder));
}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=parseInt(number/7)*7
if(parseInt((number%100)/10)!==parseInt((check%100)/10))check+=7

print(check)}

var t = readline();
for(var i = 0 ; i < t ; i++){
    var n = readline();
    if(n % 7 === 0){
        print(n);
    }
    else{
        if( (parseInt(n % 10) + parseInt(7 - n % 7)) < 10 ){
            print(parseInt(n) + parseInt(7 - n % 7));
        }
        else{
            print(parseInt(n) - parseInt(n % 7));
        }
    }
}

t= parseInt(readline()) ;
while (t--) {
	n =  parseInt(readline()) ;
	if (n<10) {
	    print(7) ;
	    continue ;
	}
	if (n%7==0) {
	print(n) ;
	}else {

	n-= n%10 ;
	ans =  0;
	for (i = 0 ; i <= 9 ; i ++ )
	{
		nw = n + i ;

		if ((nw%7) == 0 ) {
		ans = nw;
		break ;
		}
	}
	print(ans) ;
	}

	}

lines = +readline();
for (var i = 0; i < lines; i++) {
  var num = +readline();
  var old = num;
  if (num % 7 !== 0) {
    var digit = num % 10;
    if (digit + (7 - (num % 7)) <= 9) num = num + (7 - (num % 7));
    else num = num - (num % 7);
  }
  print(`${num}`);
}

var t = parseInt(readline());

for(var i = 0; i< t; i++){
    var n = parseInt(readline());
    if(n % 7 === 0) {
        print(n);
    }
    else {
        n -= n % 10;
        while(n % 7 !== 0) {
            n++;
        }
        print(n)
    }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var s = 0
    for(j = 1; j <= n; j++){
        var a = lines[j].split('')
        var b = a[a.length - 1]
        var c = lines[j] - b + 1
        if(Number(lines[j]) % 7 === 0){
            console.log(lines[j])
        }else{
            while(c % 7 !== 0){
                                c++

            }
                console.log(c)

        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var s = 0
    for(j = 1; j <= n; j++){
        var a = lines[j].split('')
        var b = a[a.length - 1]
        var c = lines[j] - b + 1
        if(Number(lines[j]) % 7 === 0){
            console.log(lines[j])
        }else{
            while(c % 7 !== 0){
                c++
                if(c % 7 === 0){
                    console.log(c)
                }
            }
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var s = 0
    for(j = 1; j <= n; j++){
        var a = lines[j].split('')
        var b = a[a.length - 1]
        var c = lines[j] - b + 1
        if(Number(lines[j]) % 7 === 0){
            console.log(lines[j])
        }else{
            while(c % 7 !== 0){
                c++
                if(c % 7 === 0){
                    console.log(c)
                    break;
                }
            }
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           c = lines[j] - 1
                  console.log(c)

       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
               console.log(c)

       }
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           c = lines[j] - 1
       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           console.log(lines[j] - 1)
       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           console.log((lines[j]) - 1)
       }else{
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
       if((lines[j] - 1) % 7 === 0 ){
           console.log((lines[j]) - 1)
       }
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j]
        while(c % 7 !== 0){
            c--
            if(c % 7 === 0){
                break;
            }
        }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       var b = a[a.length - 1]
       var c = lines[j] - b + 1
        while(c % 7 !== 0){
            c++
            if(c % 7 === 0){
                break;
            }
        }
       console.log(c)
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    for(j = 1; j <= lines[0]; j++){
            var n = lines[j];
        if(n % 7 !== 0){
        while(n % 7 !== 0){
            n++
            if(n % 7 === 0){
                break;
            }
        }
                console.log(n)

        }else{
            console.log(n)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    for(j = 1; j <= lines[0]; j++){
            var n = lines[j];
        if(n % 7 !== 0){
        while(n % 7 !== 0){
            n++
            if(n % 7 === 0){
                break;
            }
        }
        }else{
            console.log(n)
        }
        console.log(n)
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    for(j = 1; j <= lines[0]; j++){
            var n = lines[j];

        while(n % 7 !== 0){
            n++
            if(n % 7 === 0){
                break;
            }
        }
        console.log(n)
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        console.log(7)
    }
});

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var y = readline();
            var n = parseInt(y);
            if(n % 7 == 0) {
                console.log(n)
                continue;
            }
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;

            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            if(ans == undefined) {
                while(n%7 !==0) n++;
                ans = n;
            }
            console.log(ans)
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
        return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
        var y = readline();
        var n = parseInt(y);
         var s = '';
         s += n;
         var de = []
         for(var i=n;i>=1;i--) {
            if(i % 7 === 0) {
                    		var r = ''
                    	    r += i;
                    	    if(r.length < s.length) {
                    	    	var diff = s.length-r.length;
                    	    	var gh = '';
                    	    	for(var i=1;i<=diff;i++) {
                    	    		gh += 7;
                    	    	}
                    	    	gh += r;
                    	    	var sum = 0;

                    	        for(var j=0;j<gh.length;j++) {
                    		        if(gh[j] !== s[j]) sum++;
                    	        }
                    	        de[sum] = gh;
                    	        continue;
                    	    }
                    	    var sum = 0;

                    	    for(var j=0;j<r.length;j++) {
                    		    if(r[j] !== s[j]) sum++;
                    	    }
                    	    de[sum] = i;
            }

         }
         var ans
         for(var i=0;i<de.length;i++) {
                    	if(de[i] !== undefined) {
                    		ans = de[i];
                    		break;
                    	}
         }
         console.log(ans)
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var y = readline();
            var n = parseInt(y);
            if(n % 7 == 0) {
                console.log(n)
                continue;
            }
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;

            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            n -= 0;
            if(n % 7 == 0) {
                console.log(n)
                continue;
            }
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            n -= 0;
            if(n % 7 == 0) {
                console.log(n)
                continue;
            }
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=100;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            n -= 0;
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=100;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            n -= 0;
            var s = '';
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            var s = ''
            s += n;
            var de = []
            for(var i=n;i>=7;i--) {
            	if(i % 7 === 0) {
            		var r = ''
            	    r += i;
            	    if(r.length < s.length) continue;
            	    var sum = 0;

            	    for(var j=0;j<r.length;j++) {
            		    if(r[j] !== s[j]) sum++;
            	    }
            	    de[sum] = i;
            	}
            }
            var ans
            for(var i=0;i<de.length;i++) {
            	if(de[i] !== undefined) {
            		ans = de[i];
            		break;
            	}
            }
            console.log(ans)
}

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i];
        var ans = 0;
        for(j = 7; j <= 994; j+=7){
            if(Math.abs(k - j) < 7){
                ans = j;
                break;
            }
        }
        console.log(ans);
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = lines[j];
        var u = k;
        var a = 0;
        var b = 0;
        while(k % 7 !== 0){
            k++;
            a++;
        }
        while(u % 7 !== 0){
            u--;
            b++;
        }
        if(k == 21){
            k += 7;
        }
        if(a > b && u != 7){
            console.log(u);
        }else{
            console.log(k);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = Number(lines[j]);
        var u = k;
        while(k % 7 !== 0){
            k++;
        }
        if(k == 21){
            k += 7;
        }
        console.log(k);
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = Number(lines[j]);
        var u = k;
        var a = 0;
        while(k % 7 !== 0){
            k++;
            a = 1;
        }
        if(a === 0){
            k += 7;
        }
        console.log(k);
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = lines[j];
        var u = k;
        var a = 0;
        var b = 0;
        while(k % 7 !== 0){
            k++;
            a++;
        }
        while(u % 7 !== 0){
            u--;
            b++;
        }
        if(a > b && u != 7){
            console.log(u);
        }else{
            console.log(k);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = lines[j];
        var u = k;
        var a = 0;
        var b = 0;
        while(k % 7 !== 0){
            k++;
            a++;
        }
        while(u % 7 !== 0){
            u--;
            b++;
        }
        if(a > b){
            console.log(u);
        }else{
            console.log(k);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var k = lines[j];
        while(k % 7 !== 0){
            k++;
        }
        console.log(k);
    }
});

'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 main(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    let answer = 0;
    if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);
    else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)
    if(answer%10 === 0){
        answer += 7;
    }
    if((answer).toString().length < input.toString().length) answer += 7;
    console.log(parseInt(answer))
 }
}

'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 main(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    let answer = 0;
    if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);
    else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)
    if(answer%10 === 0){
        answer += 7;
    }
    if((answer).toString().length < input.toString().length) answer += 7;
    console.log(answer)
 }
}

'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 main(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    let answer = 0;
    if(parseInt(input)%7 === 0 && input[input.length-1] !== 0) answer = (input);
    else if(input[input.length-1] !== 0) answer = (Math.floor(input/7)*7)
    if(answer%10 === 0){
        answer += 7;
    }
    console.log(answer)
 }
}

'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 main(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    if(parseInt(input)%7 == 0 && input[input.length-1] != 0) console.log(input);
    else if(input[input.length-1] != 0) console.log(Math.floor(input/7)*7)
    else console.log(parseInt(input) + 1)
 }
}

'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 main(){
 let noOfInputs = (readline());
 while(noOfInputs--){
    let input = readline();
    if(parseInt(input)%7 == 0 && input[input.length-1] != 0) console.log(input);
    if(input[input.length-1] != 0) console.log(Math.floor(input/7)*7)
    else console.log(parseInt(input) + 1)
 }
}

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
function differentDigits(a, b) {
  a = "" + a;
  b = "" + b;
  if (a.length !== b.length) {
    return false;
  }
  let count = 0;
  for (let i = 0; i < a.length; i++) {
    if (a[i] !== b[i]) {
      count++;
    }
  }
  return count;
}
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0].trim());
  let i = 1;
  let dividends = [];
  for (let i = 0; i <= 999; i += 7) {
    dividends.push(i);
  }
  while (t--) {
    let n = parseInt(lines[i++].trim());
    let min = 5;
    let result;
    for (let i = 0; i < dividends.length; i++) {
      let x = differentDigits(n, dividends[i]);
      if (!x) {
        continue;
      }
      if (x < min) {
        min = x;
        result = dividends[i];
      }
    }
    console.log(result);
  }
});

r=readline;

for(r();n=r();) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var nNew = n - n%10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = +readline();
   if (n % 7 === 0) {
       print(n)
   } else {
  var atZero = n%10;
  var nNew = atZero ? n : Math.floor(n/10)*10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
   }

}

var t = parseInt(readline());

for (var i = 0; i < t; i++) {
   var n = parseInt(readline());
   if (n % 7 === 0) print(n);
  var nNew = Math.floor(n/10)*10;
  var remainder = nNew % 7;
  print(remainder ? nNew + 7 - remainder : nNew);
}

var t = parseInt(readline());

function singleTest(n, freezeLastDigit) {
      var remainder = n % 7
      if (remainder === 0) return n;
      if (freezeLastDigit) return singleTest(n+10,true)
      var lastDigit = n % 10
      var plusDigit = 7 - remainder;
      if (lastDigit + plusDigit <= 9) return n.toString(10).slice(0,-1) + (lastDigit + plusDigit);
      return singleTest(n+10,true)
}

for (var i = 0; i < t; i++) {
   var number = parseInt(readline());
   print(singleTest(number, false))
}

var t = parseInt(readline());

function singleTest(n, freezeLastDigit) {
      var remainder = n % 7
      if (remainder === 0) return n;
      if (freezeLastDigit) return singleTest(n+10,true)
      var lastDigit = n % 10
      var plusDigit = 7 - remainder;
      if (lastDigit + plusDigit <= 9) return n.toString(10).slice(0,-1) + (lastDigit + plusDigit);
      return singleTest(n+10,true)
}

for (var i = 0; i < t; i++) {
   var n = parseInt(readline());
   print(singleTest(n, false))
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff && minAns.length === num.toString().length) {
      print(minAns);
    }
    else {
      print(maxAns);
    }

  }
}

var n = parseInt(readline())
// print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff) {
      print(minAns);
    }
    else {
      print(maxAns);
    }

  }
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff) {
      print(minAns);
    }
    else {
      print(maxAns);
    }

  }
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    var minAns = (minDiv * 7).toString();
    var maxAns = (maxDiv * 7).toString();

    var minDiff = 0;
    for (var j = 0 ; j<minAns.length ; j++) {
      if (minAns[j] !== num.toString()[j]) {
        ++minDiff;
      }
    }

    var maxDiff = 0;
    for (var j = 0 ; j<maxAns.length ; j++) {
      if (maxAns[j] !== num.toString()[j]) {
        ++maxDiff;
      }
    }

    if (minDiff <= maxDiff) {
      print(minDiv * 7);
    }
    else {
      print(maxDiv * 7);
    }

  }
}
print()

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  // print(num);
  if (num % 7 === 0) {
    print(num);
  }
  else {
    var minDiv = Math.floor(num/7);
    var maxDiv = Math.ceil(num/7);
    print(minDiv);
    print(maxDiv);
  }
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  var num = parseInt(readline());
  print(num);
}

var n = parseInt(readline())
print(n);

for (var i = 0 ; i<n ; i++) {
  print(5);
}

var n = parseInt(readline())
print(n);

// for (let i = 0 ; i<n ; i++) {
//   var num = readline();
//   print(num);
// }

var numbers = readline().split(" ").map(function(x) { return parseInt(x); });
print(numbers);

var a=parseInt(readline());
for(var i=0;i<a;i++){
    var s=parseInt(readline());
    if(s%7===0){
        print(s);
    }
    else{
        var res=parseInt(s/7);
        var ans=(res+1)*7;
        print(ans);

    }
}

a=readline();
while(a-->0){
    s=readline();
    mini=100000;
    if(s%7===0){
        print(s);
    }
    else{
        res=parseInt(s/7);
        ans=(res+1)*7;
        print(s);

    }
}

var a=parseInt(readline());
for(var i=0;i<a;i++){
    var s=parseInt(readline());
    if(s%7===0){
        print(s);
    }
    else{
        var res=s/7;
        var ans=(res+1)*7;
        print(ans);

    }
}

a=readline();
while(a>0){
    s=readline();
    mini=100000;
    if(s%7===0){
        print(s);
    }
    else{
        res=s/7;
        ans=(res+1)*7;
        print(s);

    a-=1}
}

a=readline();
while(a-->0){
    s=readline();
    mini=100000;
    if(s%7===0){
        print(s);
    }
    else{
        res=s/7;
        ans=(res+1)*7;
        print(s);

    }
}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=number%7
if(check<4)result=number-check
else{
    result=number+(7-check)
}
if(result<10)result=14
if(result>999)result=994
print(result)}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=number%7
if(check<4)result=number-check
else{
    result=number+(7-check)
}
print(result)}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=parseInt(number/10)*10;
var result=parseInt(number/7)*7;
if(result<10)result=14
print(result)}

var n=parseInt(readline())
for(i=0;i<n;i++)
{var number=parseInt(readline());
var check=parseInt(number/10)*10;
var result=parseInt(number/7)*7;
print(result)}

var t = readline();
for(var i = 0 ; i < t ; i++){
    var n = readline();
    if(n % 7 === 0){
        print(n);
    }
    else{
        if( (parseInt(n % 10) + parseInt(7 - n % 7)) < 10 ){
            print(parseInt(n) + parseInt(7 - n % 7));
        }
        else{
            print(parseInt(n) - parseInt(n % 10));
        }
    }
}

var t = readline();
for(var i = 0 ; i < t ; i++){
    var n = readline();
    if(n % 7 === 0){
        print(n);
    }
    else{
        while(n % 7 !== 0){
            n++;
        }
        print(n);
    }
}

t= parseInt(readline()) ;
while (t--) {
	n =  parseInt(readline()) ;
	if (n<10) {
	    print(7) ;
	    continue ;
	}
	if (n%7==0) {
	print(n) ;
	}else {
	n/=10 ;
	n*= 10 ;
	ans =  n;
	for (i = 0 ; i <= 9 ; i ++ )
	{
		nw = n + i ;
		if (nw%7 == 0 ) {
		ans = nw;
		break ;
		}
	}
	print(ans) ;
	}

	}

t= parseInt(readline()) ;
while (t--) {
	n =  parseInt(readline()) ;
	if (n%7==0) {
	print(n) ;
	}else {
	n/=10 ;
	n*= 10 ;
	ans =  0;
	for (i = 0 ; i <= 9 ; i ++ )
	{
		nw = n + i ;
		if (nw%7 == 0 ) {
		ans = nw;
		break ;
		}
	}
	print(ans) ;
	}

	}