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

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

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

f = A("f")
a = B("a")
n = C("n")
h = B("h")
m = C("m")

f.o = n
f.r = a
a.q = m
n.q = m
h.q = n
m.q = n
assert n.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.r: B = None
        self.txt = txt

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

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

f = A("f")
a = B("a")
n = C("n")
h = B("h")
m = C("m")

f.o = n
f.r = a
a.q = m
n.q = m
h.q = n
m.q = n
assert n.q.q.q.q.txt == "n"