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

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

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

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

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

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

d.x = l
d.p = e
a.q = m
a.x = e
l.q = m
l.x = m
f.q = e
f.x = d
k.q = d
k.x = m
m.x = a
m.p = e
e.x = a
e.p = d
assert e.p.x.x.p.x.q.p.txt == "e"