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

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

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

i = A("i")
g = B("g")
f = C("f")
a = B("a")
n = B("n")

i.v = f
g.w = a
g.v = i
g.q = i
f.s = g
a.w = g
a.v = i
a.q = i
n.w = a
n.v = i
n.q = i
assert f.s.w.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

i = A("i")
g = B("g")
f = C("f")
a = B("a")
n = B("n")

i.v = f
g.w = a
g.v = i
g.q = i
f.s = g
a.w = g
a.v = i
a.q = i
n.w = a
n.v = i
n.q = i
assert f.s.w.v.txt == "i"