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

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

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

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

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

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

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

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

n.v = g
n.w = a
a.v = n
i.u = a
g.u = a
assert g.u.v.w.v.txt == "n"