// cheese-cracker [2022-01-31]

void solve(){
    long n = scan;
    long ten = (n/10) % 10;
    long d = n % 7;
    long u = 7 - d;
    long down = n - d;
    long up = n + u;
    long tend = (down / 10) % 10;
    long tenu = (up / 10) % 10;
    if(tend == ten){
        writeln(down);
    }else{
        writeln(up);
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) solve;
}

/*_________________________*That's All Folks!*__________________________*/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math, std.numeric;
string[] tk; alias tup = Tuple!(long, long);
T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
