Statistically optimal analysis of state-discretized trajectory data from multiple thermodynamic states