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

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

k = A("k")
j = B("j")
h = B("h")
l = B("l")
m = A("m")

k.r = l
k.z = l
j.x = m
j.q = k
h.x = m
h.q = m
l.x = k
l.q = m
m.r = l
m.z = h
assert m.z.x.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.z: B = None
        self.txt = txt

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

k = A("k")
j = B("j")
h = B("h")
l = B("l")
m = A("m")

k.r = l
k.z = l
j.x = m
j.q = k
h.x = m
h.q = m
l.x = k
l.q = m
m.r = l
m.z = h
assert m.z.x.z.q.txt == "m"