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

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

m = A("m")
d = B("d")
f = A("f")
e = A("e")
i = A("i")
j = A("j")
a = B("a")

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

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

m = A("m")
d = B("d")
f = A("f")
e = A("e")
i = A("i")
j = A("j")
a = B("a")

m.u = a
m.q = a
d.z = f
d.q = a
f.u = a
f.q = a
e.u = a
e.q = a
i.u = a
i.q = d
j.u = d
j.q = a
a.z = f
a.q = d
assert d.z.q.q.q.z.q.txt == "a"