#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 1e6 + 100;
const int LOG = 25;
const int mod = 924844033;
const int MX = 5e5 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;
int d[64][64];
void solve() {
int n,m;
cin >> n >> m;
for(int i=1;i<=n;++i){
for(int e=1;e<=n;++e){
d[i][e] = inf_int;
}
d[i][i] = 0;
}
vector<pair<pii,int> > edges;
for(int i=1;i<=m;++i){
int a,b,c;
cin >> a >> b >> c;
d[a][b] = c;
d[b][a] = c;
edges.pb({{a,b},c});
}
for(int k=1;k<=n;++k){
for(int i=1;i<=n;++i){
for(int e=1;e<=n;++e){
d[i][e] = min(d[i][e],d[i][k] + d[k][e]);
}
}
}
for(auto x:edges){
int a,b; tie(a,b) = x.fi;
int c = x.se;
if(d[a][b]!=c){
cout << "Impossible" <<"\n";
return;
}
}
int cnt = (int)edges.size();
/*for(int i=1;i<=n;++i){
for(int e=i+1;e<=n;++e){
if(d[i][e]!=inf_int)
cnt++;
}
}*/
cout << cnt<<"\n";
for(auto x: edges){
cout<<x.first.first<<" "<<x.first.second<<" "<<x.second<<"\n";
}
}
signed main() {
#ifdef zxc
debug = 0;
freopen("../input.txt", "r", stdin);
freopen("../output.txt", "w", stdout);
#else
#endif //zxc
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(20);
int t = 1;
cin >> t;
// t = 1;
for (int i = 1; i <= t; ++i) {
cout << "Case #" << i << ":";
solve();
// cout << "\n";
}
exit(0);
t = 1;
while (t--)
solve();
if (debug)
cerr << endl << "time : " << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}
ICAgICNwcmFnbWEgR0NDIG9wdGltaXplKCJPZmFzdCIpCiAgICAjcHJhZ21hIEdDQyB0YXJnZXQoInNzZSxzc2UyLHNzZTMsc3NzZTMsc3NlNCxwb3BjbnQsYWJtLG1teCxhdngsdHVuZT1uYXRpdmUiKQogICAgIAogICAgI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAgICAgCiAgICB1c2luZyBuYW1lc3BhY2Ugc3RkOwogICAgdHlwZWRlZiBsb25nIGxvbmcgbGw7CiAgICB0eXBlZGVmIHVuc2lnbmVkIGxvbmcgbG9uZyB1bGw7CiAgICBjb25zdCBpbnQgaW5mX2ludCA9IDFlOSArIDEwMDsKICAgIGNvbnN0IGxsIGluZl9sbCA9IDFlMTg7CiAgICB0eXBlZGVmIHBhaXI8aW50LCBpbnQ+IHBpaTsKICAgIHR5cGVkZWYgcGFpcjxsbCwgbGw+IHBsbDsKICAgIHR5cGVkZWYgbG9uZyBkb3VibGUgZGJsOwogICAgI2RlZmluZSBwYiBwdXNoX2JhY2sKICAgIGNvbnN0IGRvdWJsZSBwaSA9IDMuMTQxNTkyNjUzNTg5ODsKICAgICNkZWZpbmUgZG91dCBpZihkZWJ1ZykgY291dAogICAgI2RlZmluZSBmaSBmaXJzdAogICAgI2RlZmluZSBzZSBzZWNvbmQKICAgICNkZWZpbmUgc3Agc2V0cHJlY2lzaW9uCiAgICAjZGVmaW5lIHN6KGEpIChpbnQoYS5zaXplKCkpKQogICAgI2RlZmluZSBhbGwoYSkgYS5iZWdpbigpLGEuZW5kKCkKICAgIGJvb2wgZGVidWcgPSAwOwogICAgY29uc3QgaW50IE1BWE4gPSAxZTYgKyAxMDA7CiAgICBjb25zdCBpbnQgTE9HID0gMjU7CiAgICBjb25zdCBpbnQgbW9kID0gOTI0ODQ0MDMzOwogICAgY29uc3QgaW50IE1YID0gNWU1ICsgMTAwOwogICAgdHlwZWRlZiBsb25nIGxvbmcgbGk7CiAgICBjb25zdCBsaSBNT0QgPSAxMDAwMDAwMDAwOTQ5NzQ3NzEzbGw7CiAgICAgCiAgICBpbnQgZFs2NF1bNjRdOwogICAgdm9pZCBzb2x2ZSgpIHsKICAgICAgICBpbnQgbixtOwogICAgICAgIGNpbiA+PiBuID4+IG07CiAgICAgICAgZm9yKGludCBpPTE7aTw9bjsrK2kpewogICAgICAgICAgICBmb3IoaW50IGU9MTtlPD1uOysrZSl7CiAgICAgICAgICAgICAgICBkW2ldW2VdID0gaW5mX2ludDsKICAgICAgICAgICAgfQogICAgICAgICAgICBkW2ldW2ldID0gMDsKICAgICAgICB9CiAgICAgICAgdmVjdG9yPHBhaXI8cGlpLGludD4gPiBlZGdlczsKICAgICAgICBmb3IoaW50IGk9MTtpPD1tOysraSl7CiAgICAgICAgICAgIGludCBhLGIsYzsKICAgICAgICAgICAgY2luID4+IGEgPj4gYiA+PiBjOwogICAgICAgICAgICBkW2FdW2JdID0gYzsKICAgICAgICAgICAgZFtiXVthXSA9IGM7CiAgICAgICAgICAgIGVkZ2VzLnBiKHt7YSxifSxjfSk7CiAgICAgICAgfQogICAgIAogICAgICAgIGZvcihpbnQgaz0xO2s8PW47KytrKXsKICAgICAgICAgICAgZm9yKGludCBpPTE7aTw9bjsrK2kpewogICAgICAgICAgICAgICAgZm9yKGludCBlPTE7ZTw9bjsrK2UpewogICAgICAgICAgICAgICAgICAgIGRbaV1bZV0gPSBtaW4oZFtpXVtlXSxkW2ldW2tdICsgZFtrXVtlXSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgCiAgICAgCiAgICAgICAgZm9yKGF1dG8geDplZGdlcyl7CiAgICAgICAgICAgIGludCBhLGI7IHRpZShhLGIpID0geC5maTsKICAgICAgICAgICAgaW50IGMgPSB4LnNlOwogICAgICAgICAgICBpZihkW2FdW2JdIT1jKXsKICAgICAgICAgICAgICAgIGNvdXQgPDwgIkltcG9zc2libGUiIDw8IlxuIjsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAKICAgICAgICBpbnQgY250ID0gKGludCllZGdlcy5zaXplKCk7CiAgICAgICAgLypmb3IoaW50IGk9MTtpPD1uOysraSl7CiAgICAgICAgICAgIGZvcihpbnQgZT1pKzE7ZTw9bjsrK2UpewogICAgICAgICAgICAgICAgaWYoZFtpXVtlXSE9aW5mX2ludCkKICAgICAgICAgICAgICAgICAgICBjbnQrKzsKICAgICAgICAgICAgfQogICAgICAgIH0qLwogICAgICAgIGNvdXQgPDwgY250PDwiXG4iOwogICAgICAgIGZvcihhdXRvIHg6IGVkZ2VzKXsKICAgICAgICAgICAgY291dDw8eC5maXJzdC5maXJzdDw8IiAiPDx4LmZpcnN0LnNlY29uZDw8IiAiPDx4LnNlY29uZDw8IlxuIjsKICAgICAgICB9CiAgICAgCiAgICB9CiAgICAgCiAgICBzaWduZWQgbWFpbigpIHsKICAgICNpZmRlZiB6eGMKICAgICAgICBkZWJ1ZyA9IDA7CiAgICAgICAgZnJlb3BlbigiLi4vaW5wdXQudHh0IiwgInIiLCBzdGRpbik7CiAgICAgICAgIGZyZW9wZW4oIi4uL291dHB1dC50eHQiLCAidyIsIHN0ZG91dCk7CiAgICAjZWxzZQogICAgIAogICAgI2VuZGlmIC8venhjCiAgICAgICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgICAgICBjaW4udGllKDApOwogICAgICAgIGNvdXQudGllKDApOwogICAgICAgIGNvdXQuc2V0Zihpb3M6OmZpeGVkKTsKICAgICAgICBjb3V0LnByZWNpc2lvbigyMCk7CiAgICAgCiAgICAgICAgaW50IHQgPSAxOwogICAgICAgIGNpbiA+PiB0OwogICAgICAgIC8vIHQgPSAxOwogICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IHQ7ICsraSkgewogICAgICAgICAgICBjb3V0IDw8ICJDYXNlICMiIDw8IGkgPDwgIjoiOwogICAgICAgICAgICBzb2x2ZSgpOwogICAgICAgICAvLyAgIGNvdXQgPDwgIlxuIjsKICAgICAgICB9CiAgICAgICAgZXhpdCgwKTsKICAgICAgICB0ID0gMTsKICAgICAgICB3aGlsZSAodC0tKQogICAgICAgICAgICBzb2x2ZSgpOwogICAgICAgIGlmIChkZWJ1ZykKICAgICAgICAgICAgY2VyciA8PCBlbmRsIDw8ICJ0aW1lIDogIiA8PCAoMS4wICogY2xvY2soKSAvIENMT0NLU19QRVJfU0VDKSA8PCBlbmRsOwogICAgfQ==