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

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

k = A("k")
e = B("e")
a = B("a")
m = A("m")
d = A("d")
c = B("c")
b = B("b")

k.z = m
k.v = a
e.q = m
a.q = d
m.z = d
m.v = a
d.z = m
d.v = a
c.q = d
b.q = m
assert c.q.v.q.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.v: B = None
        self.txt = txt

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

k = A("k")
e = B("e")
a = B("a")
m = A("m")
d = A("d")
c = B("c")
b = B("b")

k.z = m
k.v = a
e.q = m
a.q = d
m.z = d
m.v = a
d.z = m
d.v = a
c.q = d
b.q = m
assert c.q.v.q.z.z.z.txt == "m"