StateListNode(State q, StateList sl) {
   this.q = q;
   this.sl = sl;
   if (sl.size++ == 0) sl.first = sl.last = this;
   else {
     sl.last.next = this;
     prev = sl.last;
     sl.last = this;
   }
 }
 void remove() {
   sl.size--;
   if (sl.first == this) sl.first = next;
   else prev.next = next;
   if (sl.last == this) sl.last = prev;
   else next.prev = prev;
 }