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

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

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

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

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

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

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

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

n.o = m
n.p = h
h.r = m
h.o = m
h.q = m
m.r = n
m.t = n
m.q = h
assert m.r.o.r.txt == "n"