def get_state_action_value(mdp, state_values, state, action, gamma):
    """ Computes Q(s,a) as in formula above """
    
    V = state_values
    s = state
    a = action
    g = gamma

    Q_sa = 0.
    for sp in mdp.get_next_states(s,a):
        P_sp_sa = mdp.get_transition_prob(s,a,sp)
        r_sa_sp = mdp.get_reward(s,a,sp)
        Q_sa += P_sp_sa * (r_sa_sp + g * V[sp])

    return Q_sa