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

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

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

f = A("f")
n = B("n")
c = C("c")
b = A("b")

f.w = c
n.s = c
n.z = b
c.z = b
c.t = n
c.p = n
b.w = c
assert b.w.z.w.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

f = A("f")
n = B("n")
c = C("c")
b = A("b")

f.w = c
n.s = c
n.z = b
c.z = b
c.t = n
c.p = n
b.w = c
assert b.w.z.w.t.txt == "n"