#include <iostream>
#include <cstdio>
#include <vector>
#define MAXN 1024
using namespace std;
int N, M, start;
vector<int> G[MAXN];
void read()
{
cin >> N >> M;
for(int i = 0; i < M; i++)
{
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
cin >> start;
}
int used[MAXN];
bool visited[MAXN];
void DFS(int u, int level, int parent)
{
used[u] = level;
visited[u] = true;
int sz = G[u].size();
for(int i = 0; i < sz; i++)
{
int v = G[u][i];
if(!visited[v])
DFS(v, level + 1, u);
if(v != parent && used[v] != 0)
cout << "Length of Cycle from " << v << " to " << u << " is " << level - used[v] + 1 << endl;
}
used[u] = 0;
}
void solve()
{
DFS(start, 1, -1);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8dmVjdG9yPgoKI2RlZmluZSBNQVhOIDEwMjQKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgTiwgTSwgc3RhcnQ7CnZlY3RvcjxpbnQ+IEdbTUFYTl07Cgp2b2lkIHJlYWQoKQp7CgljaW4gPj4gTiA+PiBNOwoKCWZvcihpbnQgaSA9IDA7IGkgPCBNOyBpKyspCgl7CgkJaW50IHUsIHY7CgkJY2luID4+IHUgPj4gdjsKCgkJR1t1XS5wdXNoX2JhY2sodik7CgkJR1t2XS5wdXNoX2JhY2sodSk7Cgl9CgoJY2luID4+IHN0YXJ0Owp9CgppbnQgdXNlZFtNQVhOXTsKYm9vbCB2aXNpdGVkW01BWE5dOwoKdm9pZCBERlMoaW50IHUsIGludCBsZXZlbCwgaW50IHBhcmVudCkKewoJdXNlZFt1XSA9IGxldmVsOwoJdmlzaXRlZFt1XSA9IHRydWU7CgoJaW50IHN6ID0gR1t1XS5zaXplKCk7Cglmb3IoaW50IGkgPSAwOyBpIDwgc3o7IGkrKykKCXsKCQlpbnQgdiA9IEdbdV1baV07Cg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