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

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

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

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

b.z = n
d.p = b
d.y = g
d.v = g
g.s = b
n.z = b
assert d.v.s.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

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

b.z = n
d.p = b
d.y = g
d.v = g
g.s = b
n.z = b
assert d.v.s.z.z.txt == "b"