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

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

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

k = A("k")
m = B("m")
h = C("h")
n = A("n")

k.q = h
k.o = n
m.q = h
m.u = h
h.q = m
n.q = h
n.o = k
assert m.q.q.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.o: A = None
        self.txt = txt

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

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

k = A("k")
m = B("m")
h = C("h")
n = A("n")

k.q = h
k.o = n
m.q = h
m.u = h
h.q = m
n.q = h
n.o = k
assert m.q.q.u.q.txt == "m"