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

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

a = A("a")
d = B("d")
j = A("j")
e = A("e")
i = A("i")
m = B("m")
k = B("k")
l = A("l")

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

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

a = A("a")
d = B("d")
j = A("j")
e = A("e")
i = A("i")
m = B("m")
k = B("k")
l = A("l")

a.p = k
a.s = k
d.q = e
d.x = e
j.p = m
j.s = m
e.p = m
e.s = m
i.p = m
i.s = d
m.q = i
m.x = a
k.q = j
k.x = j
l.p = m
l.s = d
assert m.q.p.x.p.x.s.txt == "m"