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

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

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

h = A("h")
j = B("j")
d = C("d")
a = A("a")
i = B("i")
l = C("l")
m = C("m")
g = A("g")

h.y = j
h.p = i
j.x = h
d.o = l
a.y = i
a.p = i
i.x = h
l.o = m
m.o = d
g.y = i
g.p = i
assert j.x.p.x.p.x.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: B = None
        self.txt = txt

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

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

h = A("h")
j = B("j")
d = C("d")
a = A("a")
i = B("i")
l = C("l")
m = C("m")
g = A("g")

h.y = j
h.p = i
j.x = h
d.o = l
a.y = i
a.p = i
i.x = h
l.o = m
m.o = d
g.y = i
g.p = i
assert j.x.p.x.p.x.p.x.txt == "h"