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

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

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

d = A("d")
b = B("b")
f = C("f")

d.v = b
d.x = b
d.w = f
b.v = d
f.z = b
f.p = b
assert f.p.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.x: B = None
        self.w: C = None
        self.txt = txt

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

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

d = A("d")
b = B("b")
f = C("f")

d.v = b
d.x = b
d.w = f
b.v = d
f.z = b
f.p = b
assert f.p.v.v.txt == "b"