Optimal Query Complexities for Dynamic Trace Estimation