A two-way heterogeneity model for dynamic networks