/*
ID: davidzh8
PROG: subset
LANG: JAVA
 */

import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;

//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
public class timofey {
    //Start Stub
    static long startTime = System.nanoTime();
    static int[] color;
    //Globals Go Here
    static ArrayList<Integer>[] adj;
    //Globals End
    public static void main(String[] args) throws IOException {
        FastScanner sc = new FastScanner("timofey.in", true);
        FastWriter pw = new FastWriter("timofey.out", true);
        int N= sc.ni();
        adj= new ArrayList[N];
        color= new int[N];
        for (int x=0;x <N; x++){
            adj[x]= new ArrayList<>();
        }
        for (int x=1; x<N; x++){
            int a= sc.ni()-1;
            int b= sc.ni()-1;
            adj[a].add(b);
            adj[b].add(a);
        }
        for (int x=0;x<N; x++){
            color[x]= sc.ni();
        }
        int conflictedge1=-1;
        int conflictedge2=-1;
        ArrayDeque<Integer> dq= new ArrayDeque<>();
        dq.offer(0);
        boolean visited[]= new boolean[N];
        while (dq.size()>0){
            int cur= dq.poll();
            int curcolor= color[cur];
            for (int next: adj[cur]){
                if (curcolor !=color[next]){
                    conflictedge1= cur;
                    conflictedge2= next;
                     break;
                }
                if (!visited[next]) {
                    visited[next]=true;
                    dq.offer(next);
                }
            }
        }
        if (conflictedge1==conflictedge2) {
            System.out.println("YES");
            System.out.println(0);
        }
        boolean ans=true;
        for (int i: adj[conflictedge1]){
            curcolor= color[i];
            valid=true;
            dfs(i, conflictedge1);
            ans= ans&& valid;
        }
        if (ans) {
            pw.println("YES");
            pw.println(conflictedge1);
            pw.close();
        }
        ans=true;
        for (int i: adj[conflictedge2]){
            curcolor=color[i];
            valid=true;
            dfs(i, conflictedge2);
            ans= ans&&valid;
        }
        if (ans) {
            pw.println("YES");
            pw.println(conflictedge2+1);
            pw.close();
        }
        else pw.println("NO");

        /* End Stub */
        long endTime = System.nanoTime();
        System.out.println("Execution Time: " + (endTime - startTime) / 1e9 + " s");
        pw.close();
    }
    static int curcolor=-1;
    static boolean valid=true;
    public static void dfs(int cur, int par){
        valid= valid && (color[cur]==curcolor);
        for (int i: adj[cur]){
            if (i!=par) dfs(i, cur);
        }
    }

    static class Edge implements Comparable<Edge> {
        int w;
        int a;
        int b;

        public Edge(int w, int a, int b) {
            this.w = w;
            this.a = a;
            this.b = b;

        }

        public int compareTo(Edge obj) {
            if (obj.w == w) {
                if (obj.a == a) {
                    return b - obj.b;
                }
                return a - obj.a;
            } else return w - obj.w;
        }
    }

    static class Pair implements Comparable<Pair> {
        int a;
        int b;

        public Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair obj) {
            if (obj.a == a) {
                return b - obj.b;
            } else return a - obj.a;
        }
    }

    static class SegmentTree {
        public long[] arr;
        public long[] tree;
        public int N;

        //Zero initialization
        public SegmentTree(int n) {
            N = n;
            arr = new long[N];
            tree = new long[4 * N + 1];
        }

        public long query(int treeIndex, int lo, int hi, int i, int j) {
            // query for arr[i..j]
            if (lo > j || hi < i)
                return 0;
            if (i <= lo && j >= hi)
                return tree[treeIndex];
            int mid = lo + (hi - lo) / 2;

            if (i > mid)
                return query(2 * treeIndex + 2, mid + 1, hi, i, j);
            else if (j <= mid)
                return query(2 * treeIndex + 1, lo, mid, i, j);

            long leftQuery = query(2 * treeIndex + 1, lo, mid, i, mid);
            long rightQuery = query(2 * treeIndex + 2, mid + 1, hi, mid + 1, j);

            // merge query results
            return merge(leftQuery, rightQuery);
        }

        public void update(int treeIndex, int lo, int hi, int arrIndex, long val) {
            if (lo == hi) {
                tree[treeIndex] = val;
                arr[arrIndex] = val;
                return;
            }

            int mid = lo + (hi - lo) / 2;

            if (arrIndex > mid)
                update(2 * treeIndex + 2, mid + 1, hi, arrIndex, val);
            else if (arrIndex <= mid)
                update(2 * treeIndex + 1, lo, mid, arrIndex, val);

            // merge updates
            tree[treeIndex] = merge(tree[2 * treeIndex + 1], tree[2 * treeIndex + 2]);
        }

        public long merge(long a, long b) {
            return (a + b);
        }
    }

    static class djset {
        int N;
        int[] parent;

        // Creates a disjoint set of size n (0, 1, ..., n-1)
        public djset(int n) {
            parent = new int[n];
            N = n;
            for (int i = 0; i < n; i++)
                parent[i] = i;
        }

        public int find(int v) {

            // I am the club president!!! (root of the tree)
            if (parent[v] == v) return v;

            // Find my parent's root.
            int res = find(parent[v]);

            // Attach me directly to the root of my tree.
            parent[v] = res;
            return res;
        }

        public boolean union(int v1, int v2) {

            // Find respective roots.
            int rootv1 = find(v1);
            int rootv2 = find(v2);

            // No union done, v1, v2 already together.
            if (rootv1 == rootv2) return false;

            // Attach tree of v2 to tree of v1.
            parent[rootv2] = rootv1;
            return true;
        }

    }

    static class FastScanner {
        public BufferedReader br;
        public StringTokenizer st;
        public InputStream is;

        public FastScanner(String name, boolean debug) throws IOException {
            if (debug) {
                is = System.in;
            } else {
                is = new FileInputStream(name);
            }
            br = new BufferedReader(new InputStreamReader(is), 32768);
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(next());
        }

        public long nl() {
            return Long.parseLong(next());
        }

        public double nd() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }
    }

    static class FastWriter {
        public PrintWriter pw;

        public FastWriter(String name, boolean debug) throws IOException {
            if (debug) {
                pw = new PrintWriter(System.out);
            } else {
                pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(name))));
            }
        }

        public void println(Object text) {
            pw.println(text);
        }

        public void print(Object text) {
            pw.print(text);
        }

        public void close() {
            pw.close();
        }

        public void flush() {
            pw.flush();
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SpecialPermutation2 {
    public static void main(String[] args) throws IOException{
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(r.readLine());
        while(t-- > 0){
            int n = Integer.parseInt(r.readLine());
            if(n < 4){
                System.out.println( -1 );
                continue;
            }

            int[]array = new int[n];
            int ptr = 0;

            for(int i = n - n % 2; i > 0; i -= 2)
                if(i != 4)
                    array[ptr++] = i;

            array[ptr++] = 4;

            for(int i = 1; i <= n; i += 2)
                array[ptr++] = i;

            StringBuilder b = new StringBuilder();

            for(int i : array){
                b.append(i);
                b.append(" ");
            }
            System.out.println(b);

        }
    }

}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.math.*;

//Mann Shah [ DAIICT ].
//fast io

public class Main {
	static long mod = (long) (1e9+7);
	static long mm = (long)(1e9+6);
	static long N = (long)(2*1e5);
	static InputReader in;
    static PrintWriter out;
    static Debugger deb;

    public static int lower_bound(long[] a,int k) { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1);
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1;
            else
                last = mid;
        }
    		return first;
    }

    public static int gcd(int a, int b){
	    if (a == 0)
	        return b;
	    return gcd(b % a, a);
    }

    public static long power(long x, long y, long p)
    {
        long res = 1;
        x = x % p;
       if (x == 0) return 0;
        while (y > 0) {
            if((y & 1)==1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    	public static void main(String args[] ) throws NumberFormatException, IOException  {

		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();

	    int T = in.nextInt();
	    while(T-->0) {
	    		int n = in.nextInt();
	    		int[] a = new int[n];

	    		for(int i=0;i<n;i++) {
	    			a[i]= i+1;
	    		}

	    		for(int i=1;i<n-1;i+=2) {
	    			int t = a[i];
	    			a[i] = a[i+1];
	    			a[i+1] = t;
	    		}

	    		for(int i=0;i<n-1;i+=2) {
	    			int t = a[i];
	    			a[i] = a[i+1];
	    			a[i+1]=t;
	    		}
	    		int f=0;
	    		for(int i=1;i<n;i++) {
	    			int x = Math.abs(a[i]-a[i-1]);
	    			if(x<2 || x>4) {
	    				f=1;
	    				break;
	    			}
	    		}
	    		if(f==1) {
		    		for(int i=4;i<n-1;i+=4) {
		    			int t = a[i];
		    			a[i] = a[i+1];
		    			a[i+1]=t;
		    		}
		    		f=0;
		    		for(int i=1;i<n;i++) {
		    			int x = Math.abs(a[i]-a[i-1]);
		    			if(x<2 || x>4) {
		    				f=1;
		    				break;
		    			}
		    		}
	    		}
	    		if(f==1 && n%2!=0) {
	    			f=0;
	    			int t = a[n-1];
	    			a[n-1] = a[n-2];
	    			a[n-2] = t;
	    			int tt = a[n-2];
	    			a[n-2] = a[n-3];
	    			a[n-3] = tt;
	    			for(int i=1;i<n;i++) {
		    			int x = Math.abs(a[i]-a[i-1]);
		    			if(x<2 || x>4) {
		    				f=1;
		    				break;
		    			}
		    		}
	    		}
	    		if(f==0) {
	    			for(int i=0;i<n;i++) {
	    				out.print(a[i]+" ");
	    			}
	    			out.println("");
	    		}
	    		else {
	    			out.println("-1");
	    		}

	    }

	    out.close();
	}

/* TC space

 */
		static class InputReader
	    {
	        private final InputStream stream;
	        private final byte[] buf = new byte[8192];
	        private int curChar, snumChars;
	        private SpaceCharFilter filter;

	        public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        }

	        public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        }

	        public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        }

	        public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        }

	        public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        }

	        public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        }

	        public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        }

	        public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }

	        private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        }

	        public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        }

	    }

		static class Debugger{
			public void n(int x) {
				out.println(x);
			}

			public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			}
		}

}

 class Pair {
    int x;
    int y;
    // Constructor
    public Pair(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
	@Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pair)) return false;
	    Pair p = (Pair) o;
	    return x == p.x && y == p.y;
	}
	@Override
	public int hashCode() {
		return (""+x+"-"+y).hashCode();
	}

}

//        (p1,p2) -> p1.x-p2.x Using lembda function...

//        Arrays.sort(arr, new Comparator<Pair>() {
//            @Override public int compare(Pair p1, Pair p2)
//            {
//                return p1.x - p2.x;
//            }
//        });


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.math.*;

//Mann Shah [ DAIICT ].
//fast io

public class Main {
	static long mod = (long) (1e9+7);
	static long mm = (long)(1e9+6);
	static long N = (long)(2*1e5);
	static InputReader in;
    static PrintWriter out;
    static Debugger deb;

    public static int lower_bound(long[] a,int k) { // no. of elements less than k in array.
    		int first = 0,last = a.length,mid;
        while (first < last) {
            mid = first + ((last - first) >> 1);
            if (a[mid] < k)  //lower bound. for upper use <= ( n - first)
                first = mid + 1;
            else
                last = mid;
        }
    		return first;
    }

    public static int gcd(int a, int b){
	    if (a == 0)
	        return b;
	    return gcd(b % a, a);
    }

    public static long power(long x, long y, long p)
    {
        long res = 1;
        x = x % p;
       if (x == 0) return 0;
        while (y > 0) {
            if((y & 1)==1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    	public static void main(String args[] ) throws NumberFormatException, IOException  {

		in = new InputReader(System.in);
	    out = new PrintWriter(System.out);
	    deb = new Debugger();

	    int T = in.nextInt();
	    while(T-->0) {
	    		int n = in.nextInt();

	    		if(n<=3) {
	    			out.println("-1");
	    		}
	    		else {
	    			LinkedList<Integer> q = new LinkedList();
	    			q.add(3);q.add(1);q.add(4);q.add(2);

	    			for(int i=5;i<=n;i+=2) {
	    				q.add(i);
	    			}
	    			for(int i=6;i<=n;i+=2) {
	    				q.addFirst(i);
	    			}

	    			for(int i=0;i<q.size();i++) {
	    				out.print(q.get(i)+" ");
	    			}
	    			out.println("");
	    		}

	    }

	    out.close();
	}

/* TC space

 */
		static class InputReader
	    {
	        private final InputStream stream;
	        private final byte[] buf = new byte[8192];
	        private int curChar, snumChars;
	        private SpaceCharFilter filter;

	        public InputReader(InputStream stream)
	        {
	                this.stream = stream;
	        }

	        public int snext()
	        {
	                if (snumChars == -1)
	                        throw new InputMismatchException();
	                if (curChar >= snumChars)
	                {
	                        curChar = 0;
	                        try
	                        {
	                                snumChars = stream.read(buf);
	                        } catch (IOException e)
	                        {
	                                throw new InputMismatchException();
	                        }
	                        if (snumChars <= 0)
	                                return -1;
	                }
	                return buf[curChar++];
	        }

	        public int nextInt()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                int res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public long nextLong()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                int sgn = 1;
	                if (c == '-')
	                {
	                        sgn = -1;
	                        c = snext();
	                }
	                long res = 0;
	                do
	                {
	                        if (c < '0' || c > '9')
	                                throw new InputMismatchException();
	                        res *= 10;
	                        res += c - '0';
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res * sgn;
	        }

	        public int[] nextIntArray(int n)
	        {
	                int a[] = new int[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextInt();
	                }
	                return a;
	        }

	        public long[] nextLongArray(int n)
	        {
	                long a[] = new long[n];
	                for (int i = 0; i < n; i++)
	                {
	                        a[i] = nextLong();
	                }
	                return a;
	        }

	        public ArrayList<Integer> nextArrayList(int n){
	        			ArrayList<Integer> x = new ArrayList<Integer>();
	        			for(int i=0;i<n;i++) {
	        				int v = in.nextInt();
	        				x.add(v);
	        			}
	        			return x;
	        }

	        public String readString()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                {
	                        c = snext();
	                }
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isSpaceChar(c));
	                return res.toString();
	        }

	        public String nextLine()
	        {
	                int c = snext();
	                while (isSpaceChar(c))
	                        c = snext();
	                StringBuilder res = new StringBuilder();
	                do
	                {
	                        res.appendCodePoint(c);
	                        c = snext();
	                } while (!isEndOfLine(c));
	                return res.toString();
	        }

	        public boolean isSpaceChar(int c)
	        {
	                if (filter != null)
	                        return filter.isSpaceChar(c);
	                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }

	        private boolean isEndOfLine(int c)
	        {
	                return c == '\n' || c == '\r' || c == -1;
	        }

	        public interface SpaceCharFilter
	        {
	                public boolean isSpaceChar(int ch);
	        }

	    }

		static class Debugger{
			public void n(int x) {
				out.println(x);
			}

			public void a(int[] a) {
		        StringBuilder sb = new StringBuilder();
		        for(int i=0;i<a.length;i++) {
		        		sb.append(a[i]+" ");
		        }
		        out.println(sb.toString());
			}
		}

}

 class Pair {
    int x;
    int y;
    // Constructor
    public Pair(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
	@Override
	public boolean equals(Object o) {
	    if (this == o) return true;
	    if (!(o instanceof Pair)) return false;
	    Pair p = (Pair) o;
	    return x == p.x && y == p.y;
	}
	@Override
	public int hashCode() {
		return (""+x+"-"+y).hashCode();
	}

}

//        (p1,p2) -> p1.x-p2.x Using lembda function...

//        Arrays.sort(arr, new Comparator<Pair>() {
//            @Override public int compare(Pair p1, Pair p2)
//            {
//                return p1.x - p2.x;
//            }
//        });


import java.io.*;
import java.util.Vector;

// Author- Prashant Gupta

public class E {
    public static void main(String[] args) throws IOException {
        // write your code here
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
//        Scanner sc = new Scanner(System.in);
        Reader sc = new Reader();
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            if (n == 2 || n == 3) {
                out.println(-1);
            } else {
                if (n % 2 == 0) {
                    for (int i = n - 1; i > 0; i -= 2) {
                        out.print(i + " ");
                    }
                    out.print("4 2 ");
                    for (int i = 6; i <= n; i += 2) {
                        out.print(i + " ");
                    }
                } else {
                    for (int i = n; i > 0; i -= 2) {
                        out.print(i + " ");
                    }
                    out.print("4 2 ");
                    for (int i = 6; i <= n; i += 2) {
                        out.print(i + " ");
                    }
                }
                out.println();
            }
        }
        out.close();
    }

    /*-------------------------------------------------------------------------------------*/

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long power(long x, long y) {
        long res = 1;
        while (x > 0) {
            if (y % 2 == 0) {
                x *= x;
                y /= 2;
            } else {
                res *= x;
                y--;
            }
        }
        return res;
    }

    public static long lcm(long x, long y) {
        return (x * y) / gcd(x, y);
    }

    public static int lowerBound(Vector<Integer> v, int e) {
        int start = 0, end = v.size() - 1, ind = -1;
        while (start <= end) {
            int mid = (start + end) / 2;
            if (v.get(mid) == e) {
                ind = mid;
                break;
            } else if (v.get(mid) < e) {
                ind = mid + 1;
                start = mid + 1;
            } else {
                end = mid - 1;
            }
        }
        return ind;
    }

    // Fast I/p

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }
}


import java.io.*;
import java.util.Vector;

// Author- Prashant Gupta

public class E {
    public static void main(String[] args) throws IOException {
        // write your code here
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
//        Scanner sc = new Scanner(System.in);
        Reader sc = new Reader();
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            if (n == 2 || n == 3) {
                out.println(-1);
            } else {
                if (n % 2 == 0) {
                    for (int i = n - 1; i > 0; i -= 2) {
                        out.print(i + " ");
                    }
                    out.print("4 2 ");
                    for (int i = 6; i < n; i += 2) {
                        out.print(i + " ");
                    }
                } else {
                    for (int i = n; i > 0; i -= 2) {
                        out.print(i + " ");
                    }
                    out.print("4 2 ");
                    for (int i = 6; i < n; i += 2) {
                        out.print(i + " ");
                    }
                }
                out.println();
            }
        }
        out.close();
    }

    /*-------------------------------------------------------------------------------------*/

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long power(long x, long y) {
        long res = 1;
        while (x > 0) {
            if (y % 2 == 0) {
                x *= x;
                y /= 2;
            } else {
                res *= x;
                y--;
            }
        }
        return res;
    }

    public static long lcm(long x, long y) {
        return (x * y) / gcd(x, y);
    }

    public static int lowerBound(Vector<Integer> v, int e) {
        int start = 0, end = v.size() - 1, ind = -1;
        while (start <= end) {
            int mid = (start + end) / 2;
            if (v.get(mid) == e) {
                ind = mid;
                break;
            } else if (v.get(mid) < e) {
                ind = mid + 1;
                start = mid + 1;
            } else {
                end = mid - 1;
            }
        }
        return ind;
    }

    // Fast I/p

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }
}


import java.io.*;
import java.util.Vector;

// Author- Prashant Gupta

public class E {
    public static void main(String[] args) throws IOException {
        // write your code here
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
//        Scanner sc = new Scanner(System.in);
        Reader sc = new Reader();
        int t = sc.nextInt();
        while (t-- > 0) {
            int n = sc.nextInt();
            if (n == 2 || n == 3) {
                out.println(-1);
            } else if (n == 4) {
                out.println("3 1 4 2");
            } else {
                for (int i = 1; i <= n; i += 2) {
                    out.print(i + " ");
                }
                for (int i = 2; i <= n; i += 2) {
                    out.print(i + " ");
                }
                out.println();
            }
        }
        out.close();
    }

    /*-------------------------------------------------------------------------------------*/

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long power(long x, long y) {
        long res = 1;
        while (x > 0) {
            if (y % 2 == 0) {
                x *= x;
                y /= 2;
            } else {
                res *= x;
                y--;
            }
        }
        return res;
    }

    public static long lcm(long x, long y) {
        return (x * y) / gcd(x, y);
    }

    public static int lowerBound(Vector<Integer> v, int e) {
        int start = 0, end = v.size() - 1, ind = -1;
        while (start <= end) {
            int mid = (start + end) / 2;
            if (v.get(mid) == e) {
                ind = mid;
                break;
            } else if (v.get(mid) < e) {
                ind = mid + 1;
                start = mid + 1;
            } else {
                end = mid - 1;
            }
        }
        return ind;
    }

    // Fast I/p

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }
}


import java.util.*;

public class Other1 {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0) {
			int n=sc.nextInt();
			if(n<4) {
				System.out.println(-1);
			}
			else {
				if(n%2==1) {
					for(int i=n;i>=1;i=i-2) {
						System.out.print(i+" ");
					}
					System.out.print(4+" "+2+" ");
					for(int i=6;i<n;i+=2) {
						System.out.print(i+" ");
					}
					System.out.println();
				}
				else {
					int k=n-1;
					for(int i=k;i>=1;i=i-2) {
						System.out.print(i+" ");
					}
					System.out.print(4+" "+2+" ");
					for(int i=6;i<=n;i+=2) {
						System.out.print(i+" ");
					}
					System.out.println();
				}

			}
		}

	}
}


import java.io.*;
import java.util.*;

public class C{
    public static void main(String[] args )throws IOException {
        Scanner s=new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int nq=s.nextInt();
        while(nq-->0){
            int n=s.nextInt();
            if(n<4){
                out.println(-1);
                continue;
            }
            for(int i=2-n%2;i<=n;i+=2)out.print(i+" ");
            out.print(n-3+" ");
            out.print(n-1+" ");
            for(int i=n-5;i>0;i-=2)out.print(i+" ");
            out.println();

        }

        out.close();
    }
}


import javax.xml.crypto.dsig.spec.XSLTTransformParameterSpec;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.util.*;

public class Main {

    static TreeSet<Integer>[]graph;
    static ArrayList<Integer>v;
    static BitSet visted;

    private static void dfs(int node) {
        visted.set(node);
        v.add(node);
        for (int child:graph[node]) {
            if (!visted.get(child)){
                dfs(child);
            }
        }
    }

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);

        try (PrintWriter or = new PrintWriter(System.out)) {

            int t = in.nextInt();
            outer:
            while (t-- > 0) {

                int n=in.nextInt();
                if (n<=3){
                    or.println(-1);
                    continue ;
                }
                if (n%2==0){
                    for (int i = 2; i <=n ; i+=2) {
                        or.print(i+" ");
                    }
                }else{
                    for (int i = 1; i <=n ; i+=2) {
                        or.print(i+" ");
                    }
                }
                or.print((n-3)+" "+(n-1)+" ");
                for (int i = n-5; i >=1 ; i-=2) {
                    or.print(i+" ");
                }
                or.println();

            }
        }

    }

    static long gcd(long a, long b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++) {
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec) {
                        f *= 10;
                    }
                }
            }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

class Tempo {

    int first, second, third;

    public Tempo(int first, int second, int third) {
        this.first = first;
        this.second = second;
        this.third = third;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.util.*;

public class Main {

    static class  Pair{
        ArrayList<Integer>list;
        BitSet visited;

        public Pair(ArrayList<Integer> list, BitSet visited) {
            this.list = list;
            this.visited = visited;
        }
    }
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);

        try (PrintWriter or = new PrintWriter(System.out)) {

            int t=in.nextInt();
            while (t-->0){

               int n=in.nextInt();

               LinkedList<Pair>queue=new LinkedList<>();
               ArrayList<Integer>a=null;
                for (int i = n; i >=1 ; --i) {
                    a=new ArrayList<>();
                    a.add(i);
                    BitSet s=new BitSet(n);
                    s.set(i);
                    queue.add(new Pair(a,s));
                }
                ArrayList<Integer>ans=null;
                while (!queue.isEmpty()){

                    Pair poll = queue.poll();
                    if (poll.list.size()==n){
                        ans=poll.list;
                        break;
                    }
                    int element=poll.list.get(poll.list.size()-1);
                    BitSet vis=poll.visited;
                    for (int i = 2; i <=4 ; i++) {
                       int y=element+i;

                        if (y>=1&&y<=n&&!vis.get(y)){
                           poll.list.add(y);
                            poll.visited.set(y);
                            queue.add(new Pair(poll.list,poll.visited));
                        }
                        y=element-i;
                        if (y>=1&&y<=n&&!vis.get(y)){
                            poll.list.add(y);
                            poll.visited.set(y);
                            queue.add(new Pair(poll.list,poll.visited));
                        }
                    }
                }
                if (ans!=null){
                    for(int i:ans)or.print(i+" ");
                    or.println();
                }else or.println(-1);
            }

        }

    }

    static long gcd(long a, long b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++) {
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec) {
                        f *= 10;
                    }
                }
            }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

class Tempo {

    int first, second, third;

    public Tempo(int first, int second, int third) {
        this.first = first;
        this.second = second;
        this.third = third;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.util.*;

public class Main {

    static class  Pair{
        ArrayList<Integer>list;
        BitSet visited;

        public Pair(ArrayList<Integer> list, BitSet visited) {
            this.list = list;
            this.visited = visited;
        }
    }
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);

        try (PrintWriter or = new PrintWriter(System.out)) {

            int t=in.nextInt();
            while (t-->0){

               int n=in.nextInt();

               LinkedList<Pair>queue=new LinkedList<>();
               ArrayList<Integer>a=null;
                for (int i = n; i >=1 ; --i) {
                    a=new ArrayList<>();
                    a.add(i);
                    BitSet s=new BitSet(n);
                    s.set(i);
                    queue.add(new Pair(a,s));
                }
                ArrayList<Integer>ans=null;
                while (!queue.isEmpty()){

                    Pair poll = queue.poll();
                    if (poll.list.size()==n){
                        ans=poll.list;
                        break;
                    }
                    int element=poll.list.get(poll.list.size()-1);
                    BitSet vis=poll.visited;
                    for (int i = 2; i <=4 ; i++) {
                       int y=element+i;

                        if (Math.abs(y-element)>=2&&Math.abs(y-element)<=4&&y>=1&&y<=n&&!vis.get(y)){
                            ArrayList<Integer>tmp=new ArrayList<>(poll.list);
                           tmp.add(y);
                           BitSet d=(BitSet)poll.visited.clone();
                            d.set(y);
                            queue.add(new Pair(tmp,d));
                        }
                        y=element-i;
                        if (Math.abs(y-element)>=2&&Math.abs(y-element)<=4&&y>=1&&y<=n&&!vis.get(y)){
                            ArrayList<Integer>tmp=new ArrayList<>(poll.list);
                            tmp.add(y);
                            BitSet d=(BitSet)poll.visited.clone();
                            d.set(y);
                            queue.add(new Pair(tmp,d));
                        }
                    }
                }
                if (ans!=null){
                    for(int i:ans)or.print(i+" ");
                    or.println();
                }else or.println(-1);
            }

        }

    }

    static long gcd(long a, long b)
    {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++) {
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec) {
                        f *= 10;
                    }
                }
            }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

class Tempo {

    int first, second, third;

    public Tempo(int first, int second, int third) {
        this.first = first;
        this.second = second;
        this.third = third;
    }
}


import java.util.*;
import java.io.*;
public class TestClass {
    public static void main(String args[] ) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int t=Integer.parseInt(br.readLine());
        while(t-->0)
        {
            int n=Integer.parseInt(br.readLine());
            if(n<4)
            {
                bw.write("-1\n");
                continue;
            }
            int i=2;
            for(i=2;i<=n;i=i+2)
            {
                bw.write(i+" ");
            }
            i=i-2;
            int temp=i-3;
            bw.write(temp+" ");

            if(temp+4<=n)
            bw.write((temp+4)+" ");
            bw.write((temp+2)+" ");
            for(int j=temp-2;j>=1;j=j-2)
            {
                bw.write(j+" ");
            }
            bw.newLine();
        }
        bw.close();
    }
}


// Codeforces_Round_20_B.cpp: ���������� ����� ����� ��� ����������� ����������.
//

//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> mas;
vector <int> rez;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int e;
		cin >> e;
		mas.push_back(e);
	}
	for (int i = 0; i < n; i++)
	{
		if (mas[i] == 0)
		{
			cout << '0' << ' ';
		}
		else
		{
			int l = 1000000;
			int r = 1000000;
			for (int j = i - 1; j> -1; j--)
			{
				if (mas[j] == 0)
				{
					l = i - j;
					break;
				}
			}
			for (int j = i + 1; j < n; j++)
			{
				if (mas[j] == 0)
				{
					r = j - i;
					break;
				}
			}
			cout << min(l, r) << ' ';
		}
	}
	//system("pause");
	return 0;
}


// Codeforces_Round_20_B.cpp: ���������� ����� ����� ��� ����������� ����������.
//

//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> mas;
vector <int> rez;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int e;
		cin >> e;
		mas.push_back(e);
	}
	for (int i = 0; i < n; i++)
	{
		if (mas[i] == 0)
		{
			cout << '0' << ' ';
			rez.push_back(0);
		}
		else
		{
			int r = 1000000;
			for (int j = i + 1; j < n; j++)
			{
				if (mas[j] == 0)
				{
					r = j - i;
					break;
				}
			}
			if (rez.empty())
			{
				rez.push_back(r);
				cout << r << ' ';
			}
			else
			{
				rez.push_back(min(rez[i - 1] + 1, r));
				cout << min(rez[i - 1] + 1, r) << ' ';
			}
		}
	}
	//system("pause");
	return 0;
}


// Codeforces_Round_20_B.cpp: ���������� ����� ����� ��� ����������� ����������.
//

//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector <int> mas;
vector <int> rez;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int e;
		cin >> e;
		mas.push_back(e);
	}
	for (int i = 0; i < n; i++)
	{
		if (mas[i] == 0)
		{
			cout << '0' << ' ';
		}
		else
		{
			int l = 1000000;
			int r = 1000000;
			for (int j = i - 1; j> -1; j--)
			{
				if (mas[j] == 0)
				{
					l = i - j;
					break;
				}
			}
			if (l == 1)
			{
				cout << min(l, r) << ' ';
			}
			else
			{
				int s = n;
				if (i + l <= n)
				{
					s = i + l;
				}
				for (int j = i + 1; j < s; j++)
				{
					if (mas[j] == 0)
					{
						r = j - i;
						break;
					}
				}
				cout << min(l, r) << ' ';
			}
		}
	}
	//system("pause");
	return 0;
}


#include <iostream>
using namespace std;
int min(int a, int b){
    if(a<b) return a;
    else return b;
}
int distance(int start, int end, int i){
    return min(i-start, end-i);
}
int main(){
    int n;
    cin>>n;

    int a[n];
    int b[n];
    int lenB = 0;

    for(int i=0; i<n; i++){
        cin>>a[i];
        if(a[i]==0) {
            b[lenB] = i;
            lenB++;
        }
    }

    for(int i=0; i<lenB-1; i++){
        for(int j=b[i]+1; j<b[i+1]; j++){
            a[j]=distance(b[i], b[i+1], j);
        }
    }

    if(b[0]!=0){
        for(int i=0; i<b[0]; i++){
            a[i] = b[0] - i;
        }
    }

    if(b[lenB-1]!=n-1){
        for(int i=b[lenB-1]+1; i<n; i++){
            a[i] = i - b[lenB-1];
        }
    }

    for(int i=0; i<n; i++){
        cout<<a[i]<<" ";
    }

    return 0;
}


//
//  main.cpp
//  codeforces edu round
//
//  Created by Aidos Kuanyshev on 28.04.17.
//  Copyright © 2017 Aidos Kuanyshev. All rights reserved.
//

//
//  main.cpp
//  Good Bye 2016 #2
//
//  Created by Aidos Kuanyshev on 04.01.17.
//  Copyright © 2017 Aidos Kuanyshev. All rights reserved.
//

//    South
//    10000 East
//    3500 North
//    4444 West
//    4000 North

#include <iostream>
#include <cmath>

int main() {
    long long int n;
    std::cin>>n;
    long long int a[n];
    long long int b[n], lenB=0;

    for(long long int i=0; i <n; i++){
       std::cin>>a[i];
        if(a[i] == 0){
        b[lenB] = i;
        lenB++;
        }
    }

    for(long long int i=0; i <n; i++){
        long long int min = n+1;
        if(a[i] == 0){
            std::cout<<0<<" ";
        } else {
            for(long long int j=0; j<lenB+1; j++){
                    if(min > std::abs(i-b[j])){
                        min = std::abs(i-b[j]);
                    }
                    if(min == 0) break;
            }
            std::cout<<min<<" ";
        }
    }

    return 0;
}


//
//  main.cpp
//  codeforces edu round
//
//  Created by Aidos Kuanyshev on 28.04.17.
//  Copyright © 2017 Aidos Kuanyshev. All rights reserved.
//

//
//  main.cpp
//  Good Bye 2016 #2
//
//  Created by Aidos Kuanyshev on 04.01.17.
//  Copyright © 2017 Aidos Kuanyshev. All rights reserved.
//

//    South
//    10000 East
//    3500 North
//    4444 West
//    4000 North

#include <iostream>
#include <cmath>

int main() {
    long long int n;
    std::cin>>n;
    long long int a[n];
    long long int b[n], lenB=0;

    for(long long int i=0; i <n; i++){
       std::cin>>a[i];
        if(a[i] == 0){
        b[lenB] = i;
        lenB++;
        }
    }

    for(long long int i=0; i <n; i++){
        long long int min = n+1;
        for(long long int j=0; j<lenB; j++){
            if(a[j] == 0){
                if(min > std::abs(i-b[j])){
                    min = std::abs(i-b[j]);
                }
            }

        }
        std::cout<<min<<" ";
    }

    return 0;
}


#include <iostream>
#include <cmath>

int main() {
    long long int n;
    std::cin>>n;
    long long int a[n];

    for(long long int i=0; i <n; i++){
       std::cin>>a[i];
    }

    for(long long int i=0; i <n; i++){
        long long int min = n+1;
        for(long long int j=0; j <n; j++){
            if(a[j] == 0){
                if(min > std::abs(i-j)){
                    min = std::abs(i-j);
                }
            }

        }
        std::cout<<min<<" ";
    }

    return 0;
}


//
//  main.cpp
//  codeforces edu round
//
//  Created by Aidos Kuanyshev on 28.04.17.
//  Copyright © 2017 Aidos Kuanyshev. All rights reserved.
//

//
//  main.cpp
//  Good Bye 2016 #2
//
//  Created by Aidos Kuanyshev on 04.01.17.
//  Copyright © 2017 Aidos Kuanyshev. All rights reserved.
//

//    South
//    10000 East
//    3500 North
//    4444 West
//    4000 North

#include <iostream>
#include <cmath>

int main() {
    long long int n;
    std::cin>>n;
    long long int a[n];
    long long int b[n], lenB=0;

    for(long long int i=0; i <n; i++){
       std::cin>>a[i];
        if(a[i] == 0){
        b[lenB] = i;
        lenB++;
        }
    }

    for(long long int i=0; i <n; i++){
        long long int min = n+1;
        for(long long int j=0; j<lenB+1; j++){
                if(min > std::abs(i-b[j])){
                    min = std::abs(i-b[j]);
                }

        }
        std::cout<<min<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int first=-1;
    int last=n-1;
    int* mass=new int[n];
    int step=1;
    while(a--){
        cin>>mass[k];
        if(mass[k]==0 && first==-1){
            first=k;
            last=k;
            step=1;
        }
        else if(mass[k]==0 && first!=-1){
            ind=first;
            last=k;
            int step2=1;
            for(int i=k-1;i>ind;i--){
                if(mass[i]>step2) mass[i]=step2++;
                else break;
            }
            step=1;
        }
        else{
            mass[k]=step++;
        }
        k++;
    }

    step=1;
    for(int i=first-1;i>-1;i--)
        mass[i]=step++;

    step=1;
    for(int i=0;i<n;i++){
        if(i>last) cout<<step++<<" ";
        else cout<<mass[i]<<" ";
    }

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int first=-1;
    int last=n-1;
    int* mass=new int[n];
    int step=1;
    while(a--){
        cin>>mass[k];
        if(mass[k]==0 && first==-1){
            first=k;
            last=k;
            step=1;
        }
        else if(mass[k]==0 && first!=-1){
            ind=first;
            last=k;
            int step2=1;
            for(int i=k-1;i>ind;i--){
                if(mass[i]>step2) mass[i]=step2++;
                else break;
            }
            step=1;
        }
        else{
            mass[k]=step++;
        }
        k++;
    }

    step=1;
    for(int i=first-1;i>-1;i--)
        mass[i]=step++;

    step=1;
    for(int i=last+1;i<n;i++)
        mass[i]=step++;

    for(int i=0;i<n;i++)
        cout<<mass[i]<<" ";

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int first=-1;
    int last=n-1;
    int* mass=new int[n];
    int step=1;
    while(a--){
        cin>>mass[k];
        if(mass[k]==0 && first==-1){
            first=k;
            last=k;
            step=1;
        }
        else if(mass[k]==0 && first!=-1){
            ind=first;
            last=k;
            int step2=1;
            for(int i=k-1;i>ind;i--){
                if(mass[i]>step2) mass[i]=step2++;
                else break;
            }
            step=1;
        }
        else{
            mass[k]=step++;
        }
        k++;
    }

    step=1;
    for(int i=0;i<n;i++){
        if(i<first) cout<<(first-i)<<" ";
        else if(i>last) cout<<step++<<" ";
        else cout<<mass[i]<<" ";
    }

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int* mass=new int[n];
    while(a--){
        cin>>mass[k];
        if(a==0){
             k++;
             for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                if(ind!=0)
                    mass[i]=i-ind;
                else{
                    mass[i]=k-i;
                    }
                if(ind==0 && mass[0]==0)
                     mass[i]=i-ind;
            }
            k--;
        }
        if(mass[k]==0){
            for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                if(ind!=0){
                    int temp1=k-i;
                    int temp2=i-ind;
                    mass[i]=temp1<temp2?temp1:temp2;
                }
                else{
                     mass[i]=k-i;
                }

            }

            ind=k;
        }
        k++;
    }

    for(int i=0;i<n;i++)
        cout<<mass[i]<<" ";

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int* mass=new int[n];
    while(a--){
        cin>>mass[k];
        if(mass[k]==0){
            for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                mass[i]=k-i;
            }
            ind=k;
        }
        if(a==0){
             k++;
           //  cout<<"ind "<<ind<<endl;
             for(int i=ind;i<n;i++){
                if(mass[i]==0) continue;
              //  cout<<"i "<<i<<"    "<<(i-ind)<<endl;
                mass[i]=i-ind;
            }
        }

        k++;
    }

    for(int i=0;i<n;i++)
        cout<<mass[i]<<" ";

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int first=-1;
    int last=n-1;
    int* mass=new int[n];
    int step=1;
    while(a--){
        cin>>mass[k];
        if(mass[k]==0 && first==-1){
            first=k;
            last=k;
            step=1;
        }
        else if(mass[k]==0 && first!=-1){
            ind=first;
            last=k;
            int step2=1;
            for(int i=k-1;i>ind;i--){
                if(mass[i]>step2) mass[i]=step2++;
                else break;
            }
            step=1;
        }
        else{
            mass[k]=step++;
        }
        k++;
    }

    step=1;
    for(int i=first-1;i>-1;i--)
        mass[i]=step++;

    step=1;
    for(int i=0;i<n;i++){
        if(i>last) cout<<step++;
        else cout<<mass[i]<<" ";
    }

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int* mass=new int[n];
    while(a--){
        cin>>mass[k];
        if(a==0){
             k++;
             for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                if(ind!=0)
                    mass[i]=i-ind;
                else{
                    mass[i]=k-i;
                    }
            }
            k--;
        }
        if(mass[k]==0){
            for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                if(ind!=0){
                    int temp1=k-i;
                    int temp2=i-ind;
                    mass[i]=temp1<temp2?temp1:temp2;
                }
                else{
                     mass[i]=k-i;
                }

            }

            ind=k;
        }
        k++;
    }

    for(int i=0;i<n;i++)
        cout<<mass[i]<<" ";

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int* mass=new int[n];
    while(a--){
        cin>>mass[k];
        if(a==0){
             k++;
             for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                mass[i]=i-ind;
            }
        }
        if(mass[k]==0){
            for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                mass[i]=k-i;
            }
            ind=k;
        }
        k++;
    }

    for(int i=0;i<n;i++)
        cout<<mass[i]<<" ";

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int first=-1;
    int last=n-1;
    int* mass=new int[n];
    int step=1;
    while(a--){
        cin>>mass[k];
        if(mass[k]==0 && first==-1){
            first=k;
            last=k;
            step=1;
        }
        else if(mass[k]==0 && first!=-1){
            ind=first;
            last=k;
            int step2=1;
            for(int i=k-1;i>ind;i--){
                if(mass[i]>step2) mass[i]=step2++;
                else break;
            }
            step=1;
        }
        else{
            mass[k]=step++;
        }
        k++;
    }

    //step=1;
    //for(int i=first-1;i>-1;i--)
     //   mass[i]=step++;

    step=1;
    for(int i=0;i<n;i++){
        if(i<first) cout<<(first-i)<<" ";
        else if(i>last) cout<<step++<<" ";
        else cout<<mass[i]<<" ";
    }

    delete[] mass;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, a, ind=0, k=0;
    cin>>n;
    a=n;
    int* mass=new int[n];
    while(a--){
        cin>>mass[k];
        if(a==0){
             k++;
             for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                mass[i]=i-ind;
            }
            k--;
        }
        if(mass[k]==0){
            for(int i=ind;i<k;i++){
                if(mass[i]==0) continue;
                if(ind!=0){
                    int temp1=k-i;
                    int temp2=i-ind;
                    mass[i]=temp1<temp2?temp1:temp2;
                }
                else{
                     mass[i]=k-i;
                }

            }

            ind=k;
        }
        k++;
    }

    for(int i=0;i<n;i++)
        cout<<mass[i]<<" ";

    delete[] mass;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,x=1e9,a[200005],b[200005];
int main(){
	memset(b,0x3f,sizeof(b));
	n=read();
	for(int i=0;i<n;i++)
		a[i]=read();
	for(int i=0;i<n;i++){
		if(a[i]==0)x=0;
		b[i]=x,x++;
	}
	x=1e9;
	for(int i=n-1;i>=0;i--){
		if(a[i]==0)x=0;
		b[i]=min(x,b[i]),x++;
	}
	for(int i=0;i<n;i++)
		printf("%d ",b[i]);
	return 0;
}


#include<iostream>
using namespace std;

int a[200005],b[200005];

int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		b[i]=0x7fffffff;
	}
	int q=-1;
	for(int i=0; i<n; i++)
	{
		if(a[i]==0)
			q=i;
		if(q!=-1)
		b[i]=i-q;
	}
	q=-1;
	for(int i=n-1; i>=0; i--)
	{
		if(a[i]==0)
			q=i;
		if(q!=-1)
			b[i]=min(b[i],q-i);
	}
	for(int i=0; i<n; i++)
		cout<<b[i]<<' ';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b[200001],z[200001];
int main(){
	cin>>a;
	for(int i=1;i<=a;i++){
		cin>>b[i];
		if(b[i]==0) z[i]=1;
		else b[i]=1;
	}
	for(int i=1;i<=a;i++){
		if(b[i]==0) cout<<0<<' ';
		else{
			int maxn=9999999;
			for(int j=1;j<=a;j++){
				if(z[j]) maxn=min(abs(i-j),maxn);
			}
			cout<<maxn<<' ';
		}

	}
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,a[200001];
    cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i];
    for (int i=1; i<=n; i++)
    {
        if (a[i]==0)
        {
            cout<<0<<" ";
            continue;
        }
        int l=-20000,r=20000000;
        for (int j=i-1; j>=1; j--)
        {
            if (a[j]==0)
            {
                l=j;
                break;
            }
        }
        for (int j=i+1; j<=n; j++)
        {
            if (a[j]==0)
            {
                r=j;
                break;
            }
        }
        cout<<min(i-l,r-i)<<" ";
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
long long a[200005],b[200005];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=0x7fffffff;
	}
	int q=-1;
	for(int i=0;i<n;i++){
		if(a[i]==0){
			q=i;
		}
		if(q!=-1)b[i]=i-q;
	}
	q=-1;
	for(int i=n-1;i>=0;i--){
		if(a[i]==0){
			q=i;
		}
		if(q!=-1){
			b[i]=min(b[i],q-i);
		}
	}
	for(int i=0;i<n;i++){
		cout<<b[i]<<' ';
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n, i, j;
main ()
{
    cin >> n;
    int a [n];
    for (i = 0; i < n; i ++)
    cin >> a [i];
    for (i = 0; i < n; i ++)
    {
        for (j = 0; ; j ++)
        {
            if (i - j >= 0 && a [i - j] == 0)
            {
                cout << j << " "; break;
            }
            if (i + j < n && a [i + j] == 0)
            {
                cout << j << " "; break;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int n, i, j;
vector <int> v;
vector <int> v1;
main ()
{
    cin >> n;
    int a [n];
    for (i = 0; i < n; i ++)
    {
        cin >> a [i];
        if (a [i] == 0) v.push_back (i);
    }
    if (v.size () > 1)
    {
        for (i = 0; i < v.size () - 1; i ++)
        v1.push_back ((v [i] + v[i + 1]) / 2 + 1);
    }
    v1.push_back (n);
    j = 0;
    for (i = 0; i < v1.size (); i ++)
    {
        for (; j < v1 [i]; j ++)
        {
            cout << abs (v [i] - j) << " ";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int n, i, j;
main ()
{
    cin >> n;
    int a [n];
    for (i = 0; i < n; i ++)
    cin >> a [i];
    for (i = 0; i < n; i ++)
    {
        if (a [i] == 0)
        {
            cout << 0 << " "; continue;
        }
        for (j = 0; ; j ++)
        {
            if (i - j >= 0 && a [i - j] == 0)
            {
                cout << j << " "; break;
            }
            if (i + j < n && a [i + j] == 0)
            {
                cout << j << " "; break;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int n, i, j;
vector <int> v;
vector <int> v1;
main ()
{
    cin >> n;
    int a [n];
    for (i = 0; i < n; i ++)
    {
        cin >> a [i];
        if (a [i] == 0) v.push_back (i);
    }
    if (v.size () > 1)
    {
        for (i = 0; i < v.size () - 1; i ++)
        v1.push_back ((v [i] + v[i + 1]) / 2);
    }
    v1.push_back (n);
    j = 0;
    for (i = 0; i < v1.size (); i ++)
    {
        for (; j < v1 [i]; j ++)
        {
            if (a [j] == 0) cout << "0 ";
            else cout << abs (v [i] - j) << " ";
        }
    }
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){

int a;
cin>>a;

int liczby[a-1], c, d1=a+1, d2=a+1, zera_od_przodu[a-1], zera_od_tylu[a-1];

for(int i=0;  i<a; i++){
cin>>c;
liczby[i]=c;}

for(int i=0; i<a; i++){
    if(liczby[i]==0)d1=0;
    else d1++;
    zera_od_przodu[i]=d1;

    if(liczby[a-i-1]==0)d2=0;
    else d2++;
    zera_od_tylu[a-i-1]=d2;}

for(int i=0; i<a; i++){
    if(zera_od_przodu[i]>zera_od_tylu[i])cout<<zera_od_tylu[i];
    else cout<<zera_od_przodu[i]; cout<<" ";

}
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
    int a, n, x=0;
    cin>>n;
    int zera[n], r;

    for(int i=0; i<n; i++){
        cin>>a;
        if(a==0){zera[x]=i; x++;}
        ;}
    for(int i=0; i<n; i++){
        r=n;

        for(int j=0; j<x; j++){

            if(abs(i-zera[j])<r)r=abs(i-zera[j]);
        }
        cout<<r<<" ";
    };

}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
    int a, n, x=0;
    cin>>n;
    int zera[n], r;

    for(int i=0; i<n; i++){
        cin>>a;
        if(a==0){zera[x]=i; x++;}
        ;}
         int odleglosci[x];
    for(int i=0; i<n; i++){
        for(int j=0; j<x; j++){
            odleglosci[j]=abs(i-zera[j]);
   }
        r=n;

        for(int j=0; j<x; j++){

            if(odleglosci[j]<r)r=odleglosci[j];
        }
        cout<<r<<" ";
    };

}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
    int a, n, x=0;
    cin>>n;
    int zera[n], r;

    for(int i=0; i<n; i++){
        cin>>a;
        if(a==0){zera[x]=i; x++;}
        ;}
         int odleglosci[x];
    for(int i=0; i<n; i++){
        r=n;

        for(int j=0; j<x; j++){

            if(abs(i-zera[j]<r)r=abs(i-zera[j]);
        }
        cout<<r<<" ";
    };

}


#include <iostream>
#include <cmath>
using namespace std;

int main(){

int a;
cin>>a;

int liczby[a-1], c, d1=a+1, d2=a+1, zera_od_przodu[a-1], zera_od_tylu[a-1];

for(int i=0;  i<a; i++){
cin>>c;
liczby[i]=c;}

for(int i=0; i<a; i++){
    if(liczby[i]==0)d1=0;
    else d1++;
    zera_od_przodu[i]=d1;

    if(liczby[a-i-1]==0)d2=0;
    else d2++;
    zera_od_tylu[a-i-1]=d2;}

for(int i=0; i<a; i++){
    if(zera_od_przodu[i]>zera_od_tylu[i])cout<<zera_od_tylu[i];
    else cout<<zera_od_przodu[i]<<" ";

}
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
    int a, n, x=0;
    cin>>n;
    int zera[n], r;

    for(int i=0; i<n; i++){
        cin>>a;
        if(a==0){zera[x]=i; x++;}
        ;}
         int odleglosci[x];
    for(int i=0; i<n; i++){
   }
        r=n;

        for(int j=0; j<x; j++){

            if(abs(i-zera[j]<r)r=abs(i-zera[j]);
        }
        cout<<r<<" ";
    };

}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
    int a, n, x=0;
    cin>>n;
    int zera[n], r;

    for(int i=0; i<n; i++){
        cin>>a;
        if(a==0){zera[x]=i; x++;}
        ;}
         int odleglosci[x];
    for(int i=0; i<n; i++){
        for(int j=0; j<x; j++){
            odleglosci[j]=abs(i-zera[j]);
   }
        r=n;
        for(int j=0; j<x; j++){

            if(odleglosci[j]<r)r=odleglosci[j];
        }
        cout<<r<<" ";
    };

}


#include <iostream>
#include <cmath>
using namespace std;

int main(){

int a;
cin>>a;

int liczby[a-1], c, d1=a+1, d2=a+1, zera_od_przodu[a-1], zera_od_tylu[a-1];

for(int i=0;  i<a; i++){
cin>>c;
liczby[i]=c;}

for(int i=0; i<a; i++){
    if(liczby[i]==0)d1=0;
    else d1++;
    zera_od_przodu[i]=d1;

    if(liczby[a-i-1]==0)d2=0;
    else d2++;
    zera_od_tylu[a-i-1]=d2;}

for(int i=0; i<a; i++){
    if(zera_od_przodu[i]>zera_od_tylu[i])cout<<zera_od_tylu[i];
    else cout<<zera_od_przodu[i];

}
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){
    int a, n, x=0;
    cin>>n;
    int zera[n], r;

    for(int i=0; i<n; i++){
        cin>>a;
        if(a==0){zera[x]=i; x++;}
        ;}
         int odleglosci[x];
    for(int i=0; i<n; i++){
        r=n;

        for(int j=0; j<x; j++){

            if(abs(i-zera[j])<r)r=abs(i-zera[j]);
        }
        cout<<r<<" ";
    };

}


#include <bits/stdc++.h>

// Shabdan Batyrkulov

using namespace std;

#define MAX 107
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double

const long long N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;

int a[2 * N];

int main () {
        int n; scanf ("%d", &n);
        vector <int> z;
        for (int i = 1; i <= n; i++) {
                scanf ("%d", &a[i]);
                if (a[i] == 0) {
                        z.pb(i);
                }
        }
        vector <int> d(2 * N);
        for (int i = 1; i <= n; i++) {
                int pos = lower_bound(z.begin(), z.end(), i) - z.begin();
                int pos1 = upper_bound(z.begin(), z.end(), i) - z.begin();
                pos = min(pos, (int)z.size() - 1);
                pos1 = min(pos1, (int)z.size() - 1);
                d[i] = min(abs(z[pos] - i), abs(z[pos1 + 1] - i));
        }
        for (int i = 1; i <= n; i++) {
                printf ("%d ", d[i]);
        }
}


#include <bits/stdc++.h>

// Shabdan Batyrkulov

using namespace std;

#define MAX 107
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double

const long long N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;

int a[2 * N];

int main () {
        int n; scanf ("%d", &n);
        vector <int> z;
        for (int i = 1; i <= n; i++) {
                scanf ("%d", &a[i]);
                if (a[i] == 0) {
                        z.pb(i);
                }
        }
        vector <int> d(2 * N);
        for (int i = 1; i <= n; i++) {
                int pos = lower_bound(z.begin(), z.end(), i) - z.begin();
                int pos1 = upper_bound(z.begin(), z.end(), i) - z.begin();
                pos = min(pos, (int)z.size() - 1);
                pos1 = min(pos1, (int)z.size() - 1);
                d[i] = min(abs(z[pos] - i), abs(z[pos1] - i));
        }
        for (int i = 1; i <= n; i++) {
                printf ("%d ", d[i]);
        }
}


#include <bits/stdc++.h>

// Shabdan Batyrkulov

using namespace std;

#define MAX 107
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double

const long long N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;

int a[2 * N];

int main () {
        int n; scanf ("%d", &n);
        vector <int> z;
        for (int i = 1; i <= n; i++) {
                scanf ("%d", &a[i]);
                if (a[i] == 0) {
                        z.pb(i);
                }
        }
        vector <int> d(2 * N);
        for (int i = 1; i <= n; i++) {
                if (a[i] == 0) {
                        d[i] = 0;
                } else {
                        int pos = lower_bound(z.begin(), z.end(), i) - z.begin();
                        int pos1 = upper_bound(z.begin(), z.end(), i) - z.begin();
                        if (pos >= z.size()) pos = z.size() - 1;
                        if (pos1 >= z.size()) pos1 = z.size() - 1;
                        d[i] = min(abs(z[pos] - i), abs(z[pos1] - i));
                }
        }
        for (int i = 1; i <= n; i++) {
                printf ("%d ", d[i]);
        }
}


#include <bits/stdc++.h>

// Shabdan Batyrkulov

using namespace std;

#define MAX 107
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double

const long long N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;

int a[2 * N];

int main () {
        int n; scanf ("%d", &n);
        vector <int> z;
        for (int i = 1; i <= n; i++) {
                scanf ("%d", &a[i]);
                if (a[i] == 0) {
                        z.pb(i);
                }
        }
        vector <int> d(2 * N);
        for (int i = 1; i <= n; i++) {
                if (a[i] == 0) {
                        d[i] = 0;
                } else {
                        int pos = lower_bound(z.begin(), z.end(), i) - z.begin();
                        int pos1 = upper_bound(z.begin(), z.end(), i) - z.begin();
                        if (pos >= z.size()) pos--;
                        if (pos1 >= z.size()) pos1--;
                        d[i] = min(abs(z[pos] - i), abs(z[pos1] - i));
                }
        }
        for (int i = 1; i <= n; i++) {
                printf ("%d ", d[i]);
        }
}


#include <bits/stdc++.h>

// Shabdan Batyrkulov

using namespace std;

#define MAX 107
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double

const long long N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;

int a[2 * N];

int main () {
        int n; scanf ("%d", &n);
        vector <int> z;
        for (int i = 1; i <= n; i++) {
                scanf ("%d", &a[i]);
                if (a[i] == 0) {
                        z.pb(i);
                }
        }
        vector <int> d(2 * N);
        for (int i = 1; i <= n; i++) {
                int pos = lower_bound(z.begin(), z.end(), i) - z.begin();
                int pos1 = upper_bound(z.begin(), z.end(), i) - z.begin();
                pos = min(pos, (int)z.size() - 1);
                pos1 = min(pos1, (int)z.size() - 1);
                d[i] = min(abs(z[pos] - i), abs(z[pos1 - 1] - i));
        }
        for (int i = 1; i <= n; i++) {
                printf ("%d ", d[i]);
        }
}


#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int a[10001];
int main()
{
	int n,i;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		cout<<abs(a[i]);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n;
int a[200010];
int cnt = 0;
int p[200010];
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if(a[i] == 0)
		{
			p[++cnt] = i;
		}
	}
	for(int i = p[1] - 1; i >= 0; i--)
	{
		cout << i << " ";
	}
	for(int i = 2; i <= cnt; i++)
	{
		int len = p[i] - p[i-1];
		len--;
		int up = len / 2;
		for(int j = 1; j <= up; j++)
		{
			cout << j << " ";
		}
		if(len % 2 == 1)
		{
			cout << up + 1 << " ";
		}
		for(int j = up; j >= 0; j--)
		{
			cout << j << " ";
		}
	}
	for(int i = 1; i <= n - p[cnt]; i++)
	{
		cout << i << " ";
	}
	cout << endl;
	return 0;
}


#include<iostream>
using namespace std;
int n,a[200001],b[200001],jj;
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		if(a[i]==0) jj=i;
	}
	int sum=0;
	for(int i=jj; i>0; i--)
	{
		sum++;
		if(a[i]==0) sum=0;
		b[i]=sum;
	}
	sum=0;
	for(int i=jj+1; i<=n; i++)
	{
		sum++;
		if(a[i]==0) sum=0;
		b[i]=sum;
	}
	int ok=0;
	sum=0;
	for(int i=1; i<=n; i++)
	{
		if(a[i]==0) ok=1;
		if(ok)
		{
			if(a[i]==0) sum=0;
			else sum++;
			if(b[i]>sum) b[i]=sum;
		}
	}
	ok=0;
	sum=0;
	for(int i=n; i>=1; i--)
	{
		if(a[i]==0) ok=1;
		if(ok)
		{
			if(a[i]==0) sum=0;
			else sum++;
			if(b[i]>sum) b[i]=sum;
		}
	}
	for(int i=1; i<=n; i++) cout<<b[i]<<" ";
	return 0;
}


#include <iostream>
using namespace std;

int arr[100005];

int main()
{
    for(int i = 1; i <= 10000; i++)
    {
        arr[i] = 1;
    }
    int n, cnt = 0, cnt2 = 0;
    long long min = 10000000000;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    for(int i = 1; i <= n; i++)
    {
        cnt2 = 0;
        cnt = 0;
        min = 0;
        if(arr[i] == 0)
        {
            cout << "0 ";
        }
        else
        {
            //左
            for(int j = i - 1; j >= 1; j--)
            {
                cnt++;
                if(arr[j] == 0)
                {
                    break;
                }
            }
            //右
            for(int j = i + 1; j <= n + 100; j++)
            {
                cnt2++;
                if(arr[j] == 0)
                {
                    break;
                }
            }
            if(cnt && cnt2)
            {
                min = cnt < cnt2 ? cnt : cnt2;
            }
            else
            {
                min = cnt ? cnt : cnt2;
            }
            cout << min << " ";
        }
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
/*
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}
*/
const int MAXN = 2e5 + 7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < 0)
                a[i] = INF;
        }
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                for(int j = i + 1; j < n && a[j] != 0; j++)
                    a[j] = j - i;
                for(int j = i - 1; j >= 0 && a[j] != 0; j--)
                    a[j] = min(a[j], i - j);
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
/*
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}
*/
const int MAXN = 2e5 + 7;
const int INF = 0x3f3f3f3f;
int a[MAXN];
int zero[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        int cnt = 0;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < 0)
                a[i] = INF;
            if(a[i] == 0)
                zero[cnt++] = i;
        }
        if(cnt == 1){
            for(int i = 0; i < n; i++)
                a[i] = abs(i - zero[0]);
        }
        else{
            for(int i = 0; i < zero[0]; i++)
                a[i] = zero[0] - i;
            for(int i = 0; i < cnt - 1; i++)
                for(int j = zero[i]; j < zero[i + 1]; j++){
                    a[j] = min(j - zero[i], zero[i + 1] - j);
                }
            for(int i = zero[cnt - 1]; i < n; i++)
                a[i] = i - zero[cnt - 1];
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
/*
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}
*/
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i] < 0)
                a[i] = MAXN;
        }
        for(int i = 0; i < n; i++){
            if(a[i] == 0){
                for(int j = i + 1; j < n && a[j] != 0; j++)
                    a[j] = j - i;
                for(int j = i - 1; j >= 0 && a[j] != 0; j--)
                    a[j] = min(a[j], i - j);
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}


#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
/*
int m[101][101];
int main(){
    int n, k;
    cout.tie(0);
    while(~scanf("%d%d", &n, &k)){
        memset(m, 0, sizeof(m));
        if(k > n * n){
            cout << "-1" << endl;
            continue;
        }
        for(int i = 0; i < n && k >= 2; i++){
            for(int j = 0; j < n && k >= 2; j++){
                if(i != j && m[i][j] == 0){
                    m[i][j] = m[j][i] = 1;
                    k -= 2;
                }
                else if(i == j && m[i][j] == 0){
                    m[i][j] = 1;
                    k -= 1;
                }
            }
        }
        if(k == 1){
            for(int i = 0; i < n; i++){
                if(m[i][i] == 0){
                    m[i][i] = 1;
                    break;
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                cout << m[i][j] << ' ';
            }
            cout << endl;
        }
    }
}
*/
const int MAXN = 2e5 + 7;
int a[MAXN];
int main(){
    cin.tie(0);
    cout.tie(0);
    int n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++)
            cin >> a[i];
        for(int i = 0; i < n; i++){
            if(a[i] < 0)
                a[i] = MAXN;
            bool flg = false;
            if(a[i] == 0)
                flg = true;
            for(int j = i + 1; j < n && !flg; j++)
                if(a[j] == 0){
                    a[i] = j - i;
                    flg = true;
                }
            bool tag = false;
            for(int j = i - 1; j >= 0 && !tag; j--){
                if(a[j] == 0){
                    a[i] = min(a[i], i - j);
                    tag = true;
                }
            }
        }
        for(int i = 0; i < n; i++){
            if(i == n - 1)
                cout << a[i];
            else
                cout << a[i] << ' ';
        }
        cout << endl;
    }
}