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

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

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

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

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

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

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