N,M = map(int,input().split())

par = [-1]*(N+1)


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True


def same(x,y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]

A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int,input().split())


ans = [0]*M
ans[-1] = N*(N-1)//2
for j in range(M-1,0,-1):
    if same(A[j],B[j]):
        ans[j-1] = ans[j]

    else:
        sa = size(A[j])
        sb = size(B[j])
        ans[j-1] = ans[j] - sa*sb
    unite(A[j], B[j])

for i in range(M):
    print(ans[i]) N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M par = [-1]*(N+1) par [-1]*(N+1) [-1] -1 N+1 N 1 def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x] find if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x] par[x] < 0 par[x] par x 0 return x x par[x] = find(par[x]) par[x] par x find(par[x]) find par[x] par x return par[x] par[x] par x x x def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True unite x = find(x) x find(x) find x y = find(y) y find(y) find y if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True x == y x y return False False if par[x] > par[y]:
            x,y = y,x
         par[x] > par[y] par[x] par x par[y] par y x,y = y,x x y y x par[x] += par[y] par[x] par x par[y] par y par[y] = x par[y] par y x return True True x x y y def same(x,y):
    return find(x) == find(y) same return find(x) == find(y) find(x) == find(y) find(x) find x find(y) find y x x y y def size(x):
    return -par[find(x)] size return -par[find(x)] -par[find(x)] par[find(x)] par find(x) find x x x A = [0]*M A [0]*M [0] 0 M B = [0]*M B [0]*M [0] 0 M for i in range(M):
    A[i], B[i] = map(int,input().split()) i range(M) range M A[i], B[i] = map(int,input().split()) A[i] A i map(int,input().split()) map int input().split() ().split () input split B[i] B i ans = [0]*M ans [0]*M [0] 0 M ans[-1] = N*(N-1)//2 ans[-1] ans -1 N*(N-1)//2 N*(N-1) N N-1 N 1 2 for j in range(M-1,0,-1):
    if same(A[j],B[j]):
        ans[j-1] = ans[j]

    else:
        sa = size(A[j])
        sb = size(B[j])
        ans[j-1] = ans[j] - sa*sb
    unite(A[j], B[j]) j range(M-1,0,-1) range M-1 M 1 0 -1 if same(A[j],B[j]):
        ans[j-1] = ans[j]

    else:
        sa = size(A[j])
        sb = size(B[j])
        ans[j-1] = ans[j] - sa*sb
     same(A[j],B[j]) same A[j] A j B[j] B j ans[j-1] = ans[j] ans[j-1] ans j-1 j 1 ans[j] ans j sa = size(A[j]) sa size(A[j]) size A[j] A j sb = size(B[j]) sb size(B[j]) size B[j] B j ans[j-1] = ans[j] - sa*sb ans[j-1] ans j-1 j 1 ans[j] - sa*sb ans[j] ans j sa*sb sa sb unite(A[j], B[j]) unite A[j] A j B[j] B j for i in range(M):
    print(ans[i]) i range(M) range M print(ans[i]) print ans[i] ans i ans = [0]*M [0]*M ans def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True unite def size(x):
    return -par[find(x)] def size(x):
    return -par[find(x)] size M = map(int,input().split()) map(int,input().split()) M par = [-1]*(N+1) [-1]*(N+1) par def same(x,y):
    return find(x) == find(y) def same(x,y):
    return find(x) == find(y) same A = [0]*M [0]*M A def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x] def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x] find B = [0]*M [0]*M B sb = size(B[j]) size(B[j]) sb N,M = map(int,input().split()) map(int,input().split()) N sa = size(A[j]) size(A[j]) sa
N,M = map(int,input().split())

par = [-1]*(N+1)


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True


def same(x,y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]

A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int,input().split())


ans = [0]*M
ans[-1] = N*(N-1)//2
for j in range(M-1,0,-1):
    if same(A[j],B[j]):
        ans[j-1] = ans[j]

    else:
        sa = size(A[j])
        sb = size(B[j])
        ans[j-1] = ans[j] - sa*sb
    unite(A[j], B[j])

for i in range(M):
    print(ans[i])