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

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

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

h = A("h")
j = B("j")
m = C("m")
f = C("f")

h.q = m
h.w = j
j.x = f
m.z = h
m.w = h
m.y = j
f.z = h
f.w = h
f.y = j
assert h.q.z.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.w: B = None
        self.txt = txt

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

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

h = A("h")
j = B("j")
m = C("m")
f = C("f")

h.q = m
h.w = j
j.x = f
m.z = h
m.w = h
m.y = j
f.z = h
f.w = h
f.y = j
assert h.q.z.w.x.txt == "f"