There is only little time left until the New Year! For that reason, Chef decided to make a present for his best friend. He made a connected and undirected simple graph with N$N$ vertices and M$M$ edges.
Since Chef does not like odd numbers and his friend does not like undirected graphs, Chef decided to direct each edge in one of two possible directions in such a way that the indegrees of all vertices of the resulting graph are even. The indegree of a vertex is the number of edges directed to that vertex from another vertex. As usual, Chef is busy in the kitchen, so you need to help him with directing the edges. Find one possible way to direct them or determine that it is impossible under the given conditions, so that Chef could bake a cake as a present instead.

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of each test case contains two space-separated integers N$N$ and M$M$.
- M$M$ lines follow. For each i$i$ (1≤i≤M$1 \le i \le M$), the i$i$-th of these lines contains two space-separated integers ui$u_i$ and vi$v_i$ denoting an edge between vertices ui$u_i$ and vi$v_i$.

-----Output-----
For each test case:
- If a valid way to direct the edges does not exist, print a single line containing one integer −1$-1$.
- Otherwise, print a single line containing M$M$ space-separated integers. For each valid i$i$, the i$i$-th of these integers should be 0$0$ if edge i$i$ is directed from ui$u_i$ to vi$v_i$ or 1$1$ if it is directed from vi$v_i$ to ui$u_i$.

-----Constraints-----
- 1≤T≤5$1 \le T \le 5$
- 1≤N,M≤105$1 \le N, M \le 10^5$
- 1≤ui,vi≤N$1 \le u_i, v_i \le N$ for each valid i$i$
- the graph on the input is connected, does not contain multiple edges or self-loops

-----Subtasks-----
Subtask #1 (30 points): 1≤N,M≤1,000$1 \le N, M \le 1,000$
Subtask #2 (70 points): original constraints

-----Example Input-----
2
4 4
1 2
1 3
2 4
3 4
3 3
1 2
2 3
1 3

-----Example Output-----
0 0 1 1
-1

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "import sys\r\nfrom collections import deque\r\n\r\ncroot = dict()\r\nsetnumber = dict()\r\n\r\ndef finalroot(v):\r\n    if croot[v] != v:\r\n        v = finalroot(croot[v])\r\n    return v\r\n\r\ndef union(v1,v2):\r\n    r1 = finalroot(v1)\r\n    r2 = finalroot(v2)\r\n    if r1 != r2:\r\n        if setnumber[r1] > setnumber[r2]:\r\n            croot[r2] = r1\r\n        else:\r\n            croot[r1] = r2\r\n            if setnumber[r1] == setnumber[r2]:\r\n                setnumber[r2] += 1\r\n\r\ndef minspan(n,edges):\r\n\r\n    finale = []\r\n    edgecount = {}\r\n\r\n    for i in range(n):\r\n        edgecount[i+1] = 0\r\n        setnumber[i+1] = 0\r\n        croot[i+1] = i+1\r\n\r\n    edges.sort()\r\n\r\n    for e in edges:\r\n        u,v = e\r\n        if finalroot(u) != finalroot(v):\r\n            edgecount[u] += 1\r\n            edgecount[v] += 1\r\n            finale.append((u,v))\r\n            union(u,v)\r\n\r\n    root = max(edgecount.keys(), key=(lambda k: edgecount[k]))\r\n    return set(finale),root\r\n\r\ndef main():\r\n\r\n    t = int(input())\r\n\r\n    for i in range(t):\r\n\r\n        n,m = [int(item) for item in input().split()]\r\n        e = set()\r\n        elist = []\r\n\r\n        for i in range(m):\r\n            u,v = [int(item) for item in input().split()]\r\n            elist.append((u,v))\r\n            e.add((u,v))\r\n\r\n        finale,root = minspan(n,list(e))\r\n        sroot = root\r\n        tofix = e - finale\r\n\r\n        indegree = {}\r\n        for i in range(n):\r\n            indegree[i+1] = 0\r\n\r\n        decided = set()\r\n\r\n        # randomly assign directions to edges not in min span\r\n        for t in tofix:\r\n            indegree[t[1]] += 1\r\n            decided.add((t[0],t[1]))\r\n\r\n        cf = {}\r\n        pf = {}\r\n\r\n        for i in range(n):\r\n            cf[i+1] = set()\r\n            pf[i+1] = set()\r\n\r\n        # minspan finale- create tree\r\n        # 2 dics cf - contains each node with it's child\r\n        # pf - each node with it's parent\r\n\r\n        for f in finale:\r\n            u,v = f\r\n            cf[u].add(v)\r\n            cf[v].add(u)\r\n\r\n        r = deque()\r\n        r.append(root)\r\n\r\n        while len(r) != 0:\r\n            root = r.pop()\r\n            for c in cf[root]:\r\n                r.append(c)\r\n                cf[c].remove(root)\r\n                pf[c] = root\r\n\r\n\r\n        q = deque([sroot])\r\n        st = deque()\r\n        # tree traversal\r\n        while len(q) != 0:\r\n            node = q.pop()\r\n            st.append(node)\r\n            for e in cf[node]:\r\n                q.append(e)\r\n\r\n        while len(st) != 0:\r\n            c = st.pop()\r\n            if c != sroot:\r\n                p = pf[c]\r\n                if indegree[c]%2 == 0:\r\n                    #outgoing\r\n                    decided.add((c,p))\r\n                    indegree[p] += 1\r\n                else:\r\n                    decided.add((p,c))\r\n                    indegree[c] += 1\r\n\r\n        possible = (indegree[sroot]%2 == 0)\r\n        if possible:\r\n            ans = []\r\n            for i in elist:\r\n                if i in decided:\r\n                    ans.append(0)\r\n                else:\r\n                    ans.append(1)\r\n            print(*ans)\r\n        else:\r\n            print(-1)\r\n\r\n    return 0\r\n\r\ndef __starting_point():\r\n    main()\r\n\n__starting_point()"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 17547