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

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

m = A("m")
g = B("g")
d = A("d")
k = A("k")
l = A("l")
n = A("n")
j = B("j")
c = B("c")
a = B("a")

m.o = d
g.p = n
g.x = a
d.o = k
k.o = l
l.o = m
n.o = k
j.p = l
j.x = g
c.p = m
c.x = g
a.p = l
a.x = j
assert j.p.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.p: A = None
        self.x: B = None
        self.txt = txt

m = A("m")
g = B("g")
d = A("d")
k = A("k")
l = A("l")
n = A("n")
j = B("j")
c = B("c")
a = B("a")

m.o = d
g.p = n
g.x = a
d.o = k
k.o = l
l.o = m
n.o = k
j.p = l
j.x = g
c.p = m
c.x = g
a.p = l
a.x = j
assert j.p.o.o.txt == "d"