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

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

e = A("e")
i = B("i")
f = A("f")
b = B("b")
m = B("m")
d = B("d")
g = B("g")

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

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

e = A("e")
i = B("i")
f = A("f")
b = B("b")
m = B("m")
d = B("d")
g = B("g")

e.z = i
i.u = d
i.q = f
f.z = g
b.u = m
b.q = f
m.u = b
m.q = e
d.u = i
d.q = e
g.u = d
g.q = e
assert b.u.q.z.u.q.z.u.txt == "d"