class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.u: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

e = A("e")
l = B("l")
f = A("f")
h = B("h")
m = A("m")
d = B("d")
a = A("a")
i = B("i")
b = A("b")

e.s = f
e.u = l
l.q = f
f.s = m
f.u = i
h.q = e
m.s = b
m.u = h
d.q = f
a.s = b
a.u = h
i.q = b
b.s = e
b.u = i
assert d.q.u.q.s.s.u.q.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.u: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

e = A("e")
l = B("l")
f = A("f")
h = B("h")
m = A("m")
d = B("d")
a = A("a")
i = B("i")
b = A("b")

e.s = f
e.u = l
l.q = f
f.s = m
f.u = i
h.q = e
m.s = b
m.u = h
d.q = f
a.s = b
a.u = h
i.q = b
b.s = e
b.u = i
assert d.q.u.q.s.s.u.q.s.s.txt == "f"