use std::cell::RefCell;
use std::cmp::{max, min};
use std::io::{self, stdout, BufWriter, Read, Write};
use std::iter::FromIterator;

#[allow(dead_code)]
struct Source {
    chars: Box<Iterator<Item = char>>,
}

#[allow(dead_code)]
impl Source {
    fn next_chr(&mut self) -> char {
        self.chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .next()
            .expect("eof")
    }

    fn next_str(&mut self) -> String {
        let it = self
            .chars
            .by_ref()
            .skip_while(|c| char::is_whitespace(*c))
            .take_while(|c| !char::is_whitespace(*c));
        let s = String::from_iter(it);
        if s.is_empty() {
            panic!("eof")
        } else {
            s
        }
    }

    fn from_stdin() -> Self {
        let mut data = String::new();
        io::stdin().read_to_string(&mut data).expect("Input error");
        Self::from_str(&data)
    }

    fn from_str(s: &str) -> Self {
        let data = String::from(s);
        let chars = data.chars().collect::<Vec<char>>().into_iter();
        Source {
            chars: Box::new(chars),
        }
    }
}

thread_local!(static SRC: RefCell<Source> = RefCell::new(Source::from_stdin()));

#[allow(unused_macros)]
macro_rules! input {
    ($($elem:tt)*) => {
        input_inner!(SRC, $($elem)*)
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($src:expr) => {};
    ($src:expr,) => {};
    ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {
        let mut $var = $src.with(|src| {
            let mut src = src.borrow_mut();
            parse!(src, $ty)
        });
        input_inner!($src $($rest)*)
    };
    ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {
        let $var = $src.with(|src| {
            let mut src = src.borrow_mut();
            parse!(src, $ty)
        });
        input_inner!($src $($rest)*)
    };
}

#[allow(unused_macros)]
macro_rules! parse {
    ($src:expr, ( $($ty:tt),* )) => {
        ( $(parse!($src,$ty)),* )
    };
    ($src:expr, char) => {
        $src.next_chr()
    };
    ($src:expr, [ $ty:tt; $len:expr ]) => {
        (0..$len).map(|_| parse!($src,$ty)).collect::<Vec<_>>()
    };
    ($src:expr, $ty:tt) => {
        parse_str!($src,$ty)
    };
}

#[allow(unused_macros)]
macro_rules! parse_str {
    ($src:expr, chars) => {
        $src.next_str().chars().collect::<Vec<char>>()
    };
    ($src:expr, $ty:ty) => {
        $src.next_str().parse::<$ty>().expect("Parse error")
    };
}

struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
    size: Vec<u64>,
    count: u64,
    n: u64,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let count = (n as u64 - 1) * (n as u64) / 2;
        UnionFind {
            par: (0..n).collect(),
            rank: vec![0; n],
            size: vec![1; n],
            count: count,
            n: n as u64,
        }
    }

    fn find(&mut self, a: usize) -> usize {
        if self.par[a] == a {
            a
        } else {
            let p = self.par[a];
            self.par[a] = self.find(p);
            self.par[a]
        }
    }

    fn unite(&mut self, a: usize, b: usize) {
        let a = self.find(a);
        let b = self.find(b);
        if a != b {
            self.count -= self.size[a] * (self.n - self.size[a]);
            self.count -= self.size[b] * (self.n - self.size[b] - self.size[a]);
            if self.rank[a] < self.rank[b] {
                self.par[a] = b;
                self.size[b] += self.size[a];
            } else {
                self.par[b] = a;
                if self.rank[a] == self.rank[b] {
                    self.rank[a] += 1
                }
                self.size[a] += self.size[b];
            }
            let p = self.find(a);
            let s = self.size[p];
            self.count += s * (self.n - s);
        }
    }
}

fn main() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    input! {
        n: usize, m: usize, query: [(usize,usize); m]
    }

    let mut uf = UnionFind::new(n);

    let ans: Vec<u64> = query
        .iter()
        .rev()
        .map(|&(i, j)| {
            let c = uf.count;
            uf.unite(i - 1, j - 1);
            c
        })
        .collect();

    for a in ans.iter().rev() {
        writeln!(out, "{}", a).unwrap();
    }
}


Measured memory_bytes: 17656