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

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

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

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

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

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

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