Problem:
Score : 1100 points

Problem Statement

You are given a directed graph with N vertices and M edges.
The vertices are numbered 1, 2, ..., N, and the edges are numbered 1, 2, ..., M.
Edge i points from Vertex a_i to Vertex b_i.

For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph.

Here, the reversion of Edge i means deleting Edge i and then adding a new edge that points from Vertex b_i to Vertex a_i.

Constraints

2 \leq N \leq 1000

1 \leq M \leq 200,000

1 \leq a_i, b_i \leq N

a_i \neq b_i

If i \neq j, then a_i \neq a_j or b_i \neq b_j.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print M lines. In the i-th line, if the reversion of Edge i would change the number of the strongly connected components in the graph, print diff; if it would not, print same.

Sample Input 1

3 3
1 2
1 3
2 3

Sample Output 1

same
diff
same

The number of the strongly connected components is 3 without reversion of edges, but it will become 1 if Edge 2 is reversed.

Sample Input 2

2 2
1 2
2 1

Sample Output 2

diff
diff

Reversion of an edge may result in multiple edges in the graph.

Sample Input 3

5 9
3 2
3 1
4 1
4 2
3 5
5 3
3 4
1 2
2 5

Sample Output 3

same
same
same
same
same
diff
diff
diff
diff

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int INF=0x7f7f7f7f;
const int maxn=(2e5)+10;
int n,m,tot,head[1010],nxt[maxn];
int from[maxn],to[maxn];
bool vis[1010],ans;
void add(int x) {
	tot++; nxt[tot]=head[x];
	head[x]=tot;
}
int S;
void dfs(int u) {
	vis[u]=1;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (S==i||vis[v]) continue;
		dfs(v);
	}
}
int dfn[1010],low[1010];
int sid[1010],cnt,idx;
bool inStack[1010];
stack<int> st;
void tarjan(int u) {
    dfn[u]=low[u]=++idx;
    inStack[u]=1;
    st.push(u);
    for (int i=head[u],v;i;i=nxt[i]) {
        v=to[i];
        if (dfn[v]==-1) {
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }
        else if (inStack[v])
            low[u]=min(low[u],dfn[v]);
    }
    if (dfn[u]==low[u]) {
        cnt++;
        while (1) {
            int v=st.top();
            st.pop(); inStack[v]=0;
            sid[v]=cnt;
            if (v==u) break;
        }
    }
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m);
	for (int i=1;i<=m;i++) {
		read(from[i]); read(to[i]);
		add(from[i]);
	}
	memset(dfn,-1,sizeof(dfn));
	for (int i=1;i<=n;i++) {
		if (dfn[i]==-1) tarjan(i);
	}
	int x,y;
	for (int i=1;i<=m;i++) {
		x=from[i];
		y=to[i];
		S=i;
		memset(vis,0,sizeof(vis));
		dfs(x);
		if (sid[x]==sid[y]&&vis[y]) printf("same\n");
		else if (sid[x]!=sid[y]&&!vis[y]) printf("same\n");
		else printf("diff\n");
	}
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/