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

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

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

j = A("j")
n = B("n")
g = C("g")
m = B("m")
c = C("c")
h = B("h")
i = A("i")

j.u = g
n.s = i
n.v = m
g.s = j
m.s = i
m.v = n
c.s = j
h.s = j
h.v = m
i.u = c
assert j.u.s.u.s.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

j = A("j")
n = B("n")
g = C("g")
m = B("m")
c = C("c")
h = B("h")
i = A("i")

j.u = g
n.s = i
n.v = m
g.s = j
m.s = i
m.v = n
c.s = j
h.s = j
h.v = m
i.u = c
assert j.u.s.u.s.u.txt == "g"