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

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

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

d = A("d")
e = B("e")
g = C("g")
f = C("f")

d.s = e
d.p = f
e.v = d
e.q = f
e.w = g
g.t = d
g.s = d
f.t = d
f.s = d
assert d.p.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.p: C = None
        self.txt = txt

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

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

d = A("d")
e = B("e")
g = C("g")
f = C("f")

d.s = e
d.p = f
e.v = d
e.q = f
e.w = g
g.t = d
g.s = d
f.t = d
f.s = d
assert d.p.s.s.txt == "e"