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

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

e = A("e")
m = B("m")
k = B("k")
b = B("b")
i = A("i")
d = A("d")

e.u = i
e.p = b
m.r = d
m.z = b
k.r = i
k.z = m
b.r = d
b.z = k
i.u = d
i.p = b
d.u = i
d.p = m
assert d.u.u.p.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.p: B = None
        self.txt = txt

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

e = A("e")
m = B("m")
k = B("k")
b = B("b")
i = A("i")
d = A("d")

e.u = i
e.p = b
m.r = d
m.z = b
k.r = i
k.z = m
b.r = d
b.z = k
i.u = d
i.p = b
d.u = i
d.p = m
assert d.u.u.p.r.p.r.txt == "d"