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

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

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

g = A("g")
b = B("b")
k = C("k")
m = B("m")
e = C("e")
h = A("h")
i = C("i")

g.o = h
b.x = i
b.u = h
k.r = e
m.x = i
m.u = g
e.r = k
h.o = g
i.r = k
assert k.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

g = A("g")
b = B("b")
k = C("k")
m = B("m")
e = C("e")
h = A("h")
i = C("i")

g.o = h
b.x = i
b.u = h
k.r = e
m.x = i
m.u = g
e.r = k
h.o = g
i.r = k
assert k.r.r.r.r.txt == "k"