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\ndef minspan(n,edges):\r\n\r\n    nodelist = []\r\n    finale = []\r\n\r\n    for i in range(n):\r\n        nodelist.append(set([i+1]))\r\n\r\n    for e in edges:\r\n        u = e[0]\r\n        v = e[1]\r\n\r\n        for each_set in nodelist:\r\n            if u in each_set:\r\n                save1 = each_set\r\n            if v in each_set:\r\n                save2 = each_set\r\n\r\n        if save1 != save2:\r\n            finale.append((u,v))\r\n            merged = save1 | save2\r\n            nodelist.remove(save1)\r\n            nodelist.remove(save2)\r\n            nodelist.append(merged)\r\n\r\n        if len(nodelist) == 1:\r\n            break\r\n\r\n    return finale\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 = set(minspan(n,e))\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        ## find leaf in finale\r\n        ## fix random root i = 1\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        for f in finale:\r\n            cf[f[0]].add(f[1])\r\n            cf[f[1]].add(f[0])\r\n\r\n        root = 1\r\n        visit = set([root])\r\n        visited = set()\r\n        parent = {}\r\n\r\n        #create the min span tree , every child with one parent\r\n        # root is 1\r\n        while len(visited) < n and len(visit) > 0:\r\n\r\n            v = visit.pop()\r\n            d = cf[v]\r\n            visited.add(v)\r\n\r\n            for i in d:\r\n                if i not in visited:\r\n                    parent[i] = v\r\n                    pf[v].add(i)\r\n                    visit.add(i)\r\n\r\n\r\n        leaf = set()\r\n        for k,v in cf.items():\r\n            if len(v) == 1:\r\n                leaf.add(k)\r\n\r\n\r\n        st = [1]\r\n        sc = [1]\r\n\r\n        # get traversal order from kids to parents\r\n        while len(st) < n+1:\r\n            if len(sc) == 0:\r\n                break\r\n            j = sc.pop()\r\n            for i in pf[j]:\r\n                st.append(i)\r\n                sc.append(i)\r\n\r\n        while len(st) != 1:\r\n\r\n            g = st.pop()\r\n            h = parent[g]\r\n            pair1 = (g,h)\r\n            pair2 = (h,g)\r\n\r\n            if indegree[g]%2 == 0:\r\n                #outgoing\r\n                decided.add(pair1)\r\n                indegree[h] += 1\r\n            else:\r\n                #incoming\r\n                decided.add(pair2)\r\n                indegree[g] += 1\r\n\r\n\r\n        possible = (indegree[root]%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\r\n    return 0\r\n\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: 16781