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

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

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

l = A("l")
a = B("a")
g = C("g")
i = B("i")
j = A("j")
c = A("c")

l.u = c
a.v = i
a.z = g
g.v = a
i.v = a
i.z = g
j.u = l
c.u = l
assert g.v.v.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

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

l = A("l")
a = B("a")
g = C("g")
i = B("i")
j = A("j")
c = A("c")

l.u = c
a.v = i
a.z = g
g.v = a
i.v = a
i.z = g
j.u = l
c.u = l
assert g.v.v.v.z.v.txt == "a"