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

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

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

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

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

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

e.y = a
e.p = a
d.q = m
d.r = m
a.y = e
a.p = i
k.y = e
k.p = i
i.y = k
i.p = a
m.q = d
m.r = l
l.q = d
l.r = d
assert d.q.q.r.q.r.txt == "m"