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

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

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

f = A("f")
c = B("c")
k = C("k")
d = B("d")

f.x = k
c.p = k
c.w = k
c.t = f
k.p = f
k.u = f
d.p = k
d.w = k
d.t = f
assert f.x.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

f = A("f")
c = B("c")
k = C("k")
d = B("d")

f.x = k
c.p = k
c.w = k
c.t = f
k.p = f
k.u = f
d.p = k
d.w = k
d.t = f
assert f.x.u.x.txt == "k"