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

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

n = A("n")
d = B("d")
g = B("g")
a = A("a")
c = B("c")
i = B("i")
b = A("b")
l = B("l")
h = B("h")
k = A("k")

n.o = b
d.x = k
d.p = c
g.x = b
g.p = h
a.o = k
c.x = b
c.p = l
i.x = n
i.p = h
b.o = k
l.x = k
l.p = h
h.x = a
h.p = g
k.o = a
assert d.p.p.p.x.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

n = A("n")
d = B("d")
g = B("g")
a = A("a")
c = B("c")
i = B("i")
b = A("b")
l = B("l")
h = B("h")
k = A("k")

n.o = b
d.x = k
d.p = c
g.x = b
g.p = h
a.o = k
c.x = b
c.p = l
i.x = n
i.p = h
b.o = k
l.x = k
l.p = h
h.x = a
h.p = g
k.o = a
assert d.p.p.p.x.o.o.o.txt == "k"