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

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

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

b = A("b")
g = B("g")
i = C("i")
d = C("d")

b.v = g
g.z = b
g.q = b
g.p = d
i.z = b
i.v = b
d.z = b
d.v = b
assert b.v.p.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

b = A("b")
g = B("g")
i = C("i")
d = C("d")

b.v = g
g.z = b
g.q = b
g.p = d
i.z = b
i.v = b
d.z = b
d.v = b
assert b.v.p.v.v.txt == "g"