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

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

k = A("k")
m = B("m")
i = A("i")
d = B("d")
n = A("n")
f = A("f")
c = A("c")
j = B("j")

k.r = d
k.p = i
m.u = k
m.p = i
i.r = m
i.p = k
d.u = c
d.p = f
n.r = d
n.p = i
f.r = j
f.p = i
c.r = m
c.p = n
j.u = i
j.p = i
assert i.r.p.r.p.r.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: A = None
        self.txt = txt

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

k = A("k")
m = B("m")
i = A("i")
d = B("d")
n = A("n")
f = A("f")
c = A("c")
j = B("j")

k.r = d
k.p = i
m.u = k
m.p = i
i.r = m
i.p = k
d.u = c
d.p = f
n.r = d
n.p = i
f.r = j
f.p = i
c.r = m
c.p = n
j.u = i
j.p = i
assert i.r.p.r.p.r.u.r.txt == "d"