#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int testcase = 0;
cin >> testcase;
while(testcase--){
int n, m;
cin >> n >> m;
vector<vector<int>> G(n+1);
for(int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
if (x <= n && y <= n) {
G[x].push_back(y);
G[y].push_back(x);
}
}
int source=1;
queue<int> q;
q.push(source);
int used[n+1] = {0};
used[source] = 1;
int lvl[n+1] = {0};
int ways[n+1] = {0};
ways[source] = 1;
while(!q.empty()){
int v = q.front();
q.pop();
for(auto x: G[v]){
if(used[x] == 0){
q.push(x);
used[x] = 1;
lvl[x] = lvl[v] + 1;
ways[x] = ways[v];
}
else if(used[x] == 1 && lvl[v] + 1 == lvl[x]){
ways[x] = (ways[x] + ways[v]) % MOD;
}
}
}
for(int i = 1; i <= n; i++){
cout << i << " " << ways[i] << "\n";
}
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcgaW50CiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKCmludCBtYWluKCl7CiNpZm5kZWYgT05MSU5FX0pVREdFCiAgICBmcmVvcGVuKCJpbnB1dC50eHQiLCJyIixzdGRpbik7CiAgICBmcmVvcGVuKCJvdXRwdXQudHh0IiwidyIsc3Rkb3V0KTsKI2VuZGlmCgogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOyBjb3V0LnRpZShOVUxMKTsKICAgIGludCB0ZXN0Y2FzZSA9IDA7CiAgICBjaW4gPj4gdGVzdGNhc2U7CiAgICB3aGlsZSh0ZXN0Y2FzZS0tKXsKICAgICAgICBpbnQgbiwgbTsKICAgICAgICBjaW4gPj4gbiA+PiBtOwogICAgICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gRyhuKzEpOyAgCiAgICAgICAgZm9yKGludCBpID0gMTsgaSA8PSBtOyBpKyspewogICAgICAgICAgICBpbnQgeCwgeTsKICAgICAgICAgICAgY2luID4+IHggPj4geTsKICAgICAgICAgICAgaWYgKHggPD0gbiAmJiB5IDw9IG4pIHsKICAgICAgICAgICAgICAgIEdbeF0ucHVzaF9iYWNrKHkpOwogICAgICAgICAgICAgICAgR1t5XS5wdXNoX2JhY2soeCk7ICAKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaW50IHNvdXJjZT0xOwogICAgICAgIHF1ZXVlPGludD4gcTsKICAgICAgICBxLnB1c2goc291cmNlKTsKICAgICAgICAKICAgICAgICBpbnQgdXNlZFtuKzFdID0gezB9OyAgCiAgICAgICAgdXNlZFtzb3VyY2VdID0gMTsKICAgICAgICAKICAgICAgICBpbnQgbHZsW24rMV0gPSB7MH07IAogICAgICAgIGludCB3YXlzW24rMV0gPSB7MH07ICAKICAgICAgICB3YXlzW3NvdXJjZV0gPSAxOyAgICAgCiAgICAgICAgCiAgICAgICAgd2hpbGUoIXEuZW1wdHkoKSl7CiAgICAgICAgICAgIGludCB2ID0gcS5mcm9udCgpOwogICAgICAgICAgICBxLnBvcCgpOwogICAgICAgICAgICAKICAgICAgICAgICAgZm9yKGF1dG8geDogR1t2XSl7CiAgICAgICAgICAgICAgICBpZih1c2VkW3hdID09IDApeyAgCiAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHgpOwogICAgICAgICAgICAgICAgICAgIHVzZWRbeF0gPSAxOwogICAgICAgICAgICAgICAgICAgIGx2bFt4XSA9IGx2bFt2XSArIDE7CiAgICAgICAgICAgICAgICAgICAgd2F5c1t4XSA9IHdheXNbdl07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlIGlmKHVzZWRbeF0gPT0gMSAmJiBsdmxbdl0gKyAxID09IGx2bFt4XSl7IAogICAgICAgICAgICAgICAgICAgIHdheXNbeF0gPSAod2F5c1t4XSArIHdheXNbdl0pICUgTU9EOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKXsKICAgICAgICAgICAgY291dCA8PCBpIDw8ICIgIiA8PCB3YXlzW2ldIDw8ICJcbiI7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIDA7Cn0K