Let N be the sum of all positive integers q of the form q=p^k with prime p, such that for at least four different integer values of x from 1 to q,

x^3−3x≡123(modq).
What are the last 3 digits of N?