There are n cities in Berland. The city numbered 1 is the capital. Some pairs of cities are connected by a one-way road of length 1.

Before the trip, Polycarp for each city found out the value of d_i — the shortest distance from the capital (the 1-st city) to the i-th city.

Polycarp begins his journey in the city with number s and, being in the i-th city, chooses one of the following actions: 

  1. Travel from the i-th city to the j-th city if there is a road from the i-th city to the j-th and d_i < d_j; 
  2. Travel from the i-th city to the j-th city if there is a road from the i-th city to the j-th and d_i ≥ d_j; 
  3. Stop traveling. 



Since the government of Berland does not want all people to come to the capital, so Polycarp no more than once can take the second action from the list. in other words, he can perform the second action 0 or 1 time during his journey. Polycarp, on the other hand, wants to be as close to the capital as possible.

<image>

For example, if n = 6 and the cities are connected, as in the picture above, then Polycarp could have made the following travels (not all possible options): 

  * 2 → 5 → 1 → 2 → 5; 
  * 3 → 6 → 2; 
  * 1 → 3 → 6 → 2 → 5. 



Polycarp wants for each starting city i to find out how close he can get to the capital. More formally: he wants to find the minimal value of d_j that Polycarp can get from the city i to the city j according to the rules described above.

Input

The first line contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases. Then t test cases follow.

Each test case is preceded by an empty line.

The first line of each test case contains two integers n (2 ≤ n ≤ 2 ⋅ 10^5) and m (1 ≤ m ≤ 2 ⋅ 10^5) — number of cities and roads, respectively.

This is followed by m lines describing the roads. Each road is characterized by two integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the numbers of cities connected by a one-way road.

It is guaranteed that the sums of n and m over all test cases do not exceed 2 ⋅ 10^5.

It is guaranteed that for each pair of different cities (u, v) there is at most one road from u to v (but a pair of roads from u to v and from v to u — is valid).

It is guaranteed that there is a path from the capital to all cities.

Output

For each test case, on a separate line output n numbers, the i-th of which is equal to the minimum possible distance from the capital to the city where Polycarp ended his journey.

Example

Input


3

6 7
1 2
1 3
2 5
2 4
5 1
3 6
6 2

2 2
1 2
2 1

6 8
1 2
1 5
2 6
6 1
2 3
3 4
4 2
5 4


Output


0 0 1 2 0 1 
0 0 
0 0 2 1 1 0 
//  zukonit14 - Kunal Raut

#include<bits/stdc++.h>
using namespace std;

// #include "ext/pb_ds/assoc_container.hpp"
// #include "ext/pb_ds/tree_policy.hpp"
// using namespace __gnu_pbds;

// template<class T>
// using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

// template<class key, class value, class cmp = std::less<key>>
// using omap = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

/*/-----------------------------DEFINES----------------------------------/*/

#define ll                  long long
#define ld                  long double
#define pb                  push_back
#define mp                  make_pair
#define fi                  first
#define se                  second
#define pi                  3.1415926535
#define all(v)              v.begin(), v.end()
#define allr(v)             v.rbegin(), v.rend()
#define ms(s, n)            memset(s, n, sizeof(s))
#define prec(n)             fixed<<setprecision(n)
#define forci(p,n)          for(ll i=p;i<(ll)n;i++)
#define forcj(p,n)          for(ll j=p;j<(ll)n;j++)
#define forc(i,p,n)            for(ll i=p;i<(ll)n;i++)
#define bolt                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a)             __builtin_popcountll(a)
#define djokovic            freopen("input00.txt", "r", stdin);freopen("output00.txt", "w", stdout);
#define inrange(i,a,b)      ((i>=min(a,b)) && (i<=max(a,b)))
#define sz(a)               (ll)a.size()
#define sum(a)              ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)             (*min_element((a).begin(), (a).end()))
#define maxe(a)             (*max_element((a).begin(), (a).end()))
#define mini(a)             ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)             ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x)          ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x)          ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
clock_t time_p              = clock();
void rtime()                {time_p = clock() - time_p; cout << "\nTime Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "s\n";}


/*/-----------------------------INLINE FUNCTIONS----------------------------------/*/

inline ll gcd(ll a, ll b)          {if (b == 0) return a;    return gcd(b, a % b);}
inline ll lcm(ll a, ll b)          {return (a / gcd(a, b) * b);}
inline bool isprime(ll n)            {ll i; for (i = 2; i <= sqrt(n); i++) {if (n % i == 0)return false;} return true;}
inline ll ceil(ll num, ll den)      {return ((num + den - 1) / den);}

/*/-----------------------------TRACE FUNCTIONS----------------------------------/*/

template<class T> ostream& operator<<(ostream &os, string V) {
    os << "[ ";
    for (auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S) os << s << " ";
    return os << "}";
}
template<class T> ostream& operator<<(ostream &os, multiset<T> S) {
    os << "{ ";
    for (auto s : S) os << s << " ";
    return os << "}";
}
template<class T, class T1> ostream& operator<<(ostream &os, map<T, T1> S) {
    os << "{ ";
    for (auto s : S) os << "(" << s.first << "," << s.second << ") ";
    return os << "}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
#define tracearr(a,n)  {cout << #a<<" : ";cout<<"[ ";for (ll i = 0; i < n; i++) cout << a[i] << " ";cout << "]\n";}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

/*/-----------------------------MODULAR ARITHMETIC----------------------------------/*/

// const ll modx = 1e9 + 7;
const ll modx = 998244353;
const ll mod = modx;
inline ll add(ll x, ll y, ll mod = modx) {
    x += y;
    if (x >= mod) return x - mod;
    return x % mod;
}
inline ll sub(ll x, ll y, ll mod = modx) {
    x -= y;
    if (x < 0) return x + mod;
    return x;
}
inline ll mul(ll x, ll y, ll mod = modx) {
    return (x * 1ll * y) % mod;
}
inline ll expo(ll x, ll y, ll mod = modx) {
    ll ans = 1;
    while (y) {
        if (y & 1) ans = mul(ans, x, mod);
        x = mul(x, x, mod);
        y >>= 1;
    }
    return ans % mod;
}
inline ll inv(ll x, ll mod = modx) {
    return expo(x, mod - 2, mod);
}
/*/-----------------------------CODE BEGINS----------------------------------/*/
#define int long long
ll rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
ll cc[] = {1, 1, 0, -1, -1, -1, 0, 1};  //x-y -> URDL , row-column -> RDLU; 0-based;

const ll MAXN = 2e5 + 100, MAX2N = 2e3 + 10, LG = 20, INF = 2e18, base = 33;
const int N = 1e5 + 5;
ll n, m, k, q, x,  y, z, a[MAXN], d[MAXN], p[MAXN], vis[MAXN];
vector<ll>g[MAXN]; ll dp[MAXN];
void fill()
{
    for (ll i = 0; i <= n; i++)
        d[i] = -1, p[i] = -1, dp[i] = 0, g[i].clear(), vis[i] = 0;
}
void dijkstra(ll s) {
    d[s] = 0;
    queue<ll>q;
    q.push(s);
    while (!q.empty()) {
        ll v = q.front();
        q.pop();
        for (auto u : g[v])
        {
            if (d[u] == -1)
            {
                d[u] = d[v] + 1;
                q.push(u);
            }
        }
    }
}
void dfs(ll s)
{
    vis[s] = 1;
    dp[s] = d[s];
    for (auto to : g[s])
    {
        if (!vis[to] && d[s] < d[to]) {
            dfs(to);
        }
        if (d[s] < d[to])
            dp[s] = min(dp[s], dp[to]);
        else
            dp[s] = min(dp[s], d[to]);
    }
}
void solve()
{
    cin >> n >> m;
    fill();
    for (ll i = 0; i < m; i++)
    {
        ll u, v; cin >> u >> v; --u, --v;
        g[u].pb(v);
    }
    dijkstra(0);
    dfs(0);
    for (ll i = 0; i < n; i++)
        cout << dp[i] << " ";
    cout << "\n";
}
signed main()
{
    bolt;
#ifndef ONLINE_JUDGE
    djokovic;
#endif
    ll t;
    t = 1;
    cin >> t;
    for (ll i = 1; i <= t; i++)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    //rtime();
}
