Topological quantum field theory and polynomial identities for graphs on the torus