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

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

l = A("l")
h = B("h")
f = A("f")

l.z = f
l.q = f
h.t = f
h.r = l
f.z = l
f.q = l
assert h.r.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.q: A = None
        self.txt = txt

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

l = A("l")
h = B("h")
f = A("f")

l.z = f
l.q = f
h.t = f
h.r = l
f.z = l
f.q = l
assert h.r.z.z.txt == "l"