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

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

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

i = A("i")
l = B("l")
g = C("g")
f = C("f")

i.s = l
l.v = g
l.p = i
l.w = i
g.p = i
g.s = f
f.p = i
f.s = g
assert l.v.p.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

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

i = A("i")
l = B("l")
g = C("g")
f = C("f")

i.s = l
l.v = g
l.p = i
l.w = i
g.p = i
g.s = f
f.p = i
f.s = g
assert l.v.p.s.v.txt == "g"