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

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

class C:
    def __init__(self, txt: str):
        self.y: B = None
        self.w: B = None
        self.txt = txt

h = A("h")
d = B("d")
l = C("l")
b = A("b")

h.q = b
h.x = l
d.z = b
l.y = d
l.w = d
b.q = h
b.x = l
assert b.q.x.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.x: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: B = None
        self.w: B = None
        self.txt = txt

h = A("h")
d = B("d")
l = C("l")
b = A("b")

h.q = b
h.x = l
d.z = b
l.y = d
l.w = d
b.q = h
b.x = l
assert b.q.x.y.z.txt == "b"