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

class B:
    def __init__(self, txt: str):
        self.s: C = None
        self.y: C = None
        self.o: C = None
        self.txt = txt

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

j = A("j")
k = B("k")
m = C("m")
f = A("f")
h = C("h")

j.o = f
j.w = f
j.z = m
k.s = m
k.y = m
k.o = h
m.r = h
f.o = j
f.w = j
f.z = m
h.r = m
assert m.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: C = None
        self.w: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: C = None
        self.y: C = None
        self.o: C = None
        self.txt = txt

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

j = A("j")
k = B("k")
m = C("m")
f = A("f")
h = C("h")

j.o = f
j.w = f
j.z = m
k.s = m
k.y = m
k.o = h
m.r = h
f.o = j
f.w = j
f.z = m
h.r = m
assert m.r.r.r.r.txt == "m"