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

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

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

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

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

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

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

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

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