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

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

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

h = A("h")
n = B("n")
m = C("m")
a = C("a")
b = A("b")
c = C("c")

h.o = n
n.q = c
n.p = b
n.t = h
m.x = n
m.y = c
a.x = n
a.y = c
b.o = n
c.x = n
c.y = m
assert b.o.p.o.p.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

h = A("h")
n = B("n")
m = C("m")
a = C("a")
b = A("b")
c = C("c")

h.o = n
n.q = c
n.p = b
n.t = h
m.x = n
m.y = c
a.x = n
a.y = c
b.o = n
c.x = n
c.y = m
assert b.o.p.o.p.o.p.txt == "b"