Loop over all pairs with quadratic terms