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

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

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

b = A("b")
m = B("m")
i = C("i")
g = B("g")
a = A("a")

b.u = i
b.v = m
m.x = g
i.o = b
i.u = g
i.z = a
g.x = m
a.u = i
a.v = m
assert g.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.v: B = None
        self.txt = txt

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

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

b = A("b")
m = B("m")
i = C("i")
g = B("g")
a = A("a")

b.u = i
b.v = m
m.x = g
i.o = b
i.u = g
i.z = a
g.x = m
a.u = i
a.v = m
assert g.x.x.x.x.txt == "g"