Thousands of Scots are waiting more than eight hours to be seen at an A&E ward before being admitted or discharged.