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

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

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

j.r = b
g.u = k
g.p = m
k.r = m
b.u = j
b.p = m
l.r = b
d.r = e
a.u = d
a.p = f
f.u = k
f.p = g
e.u = k
e.p = m
m.u = d
m.p = g
assert f.u.r.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

j.r = b
g.u = k
g.p = m
k.r = m
b.u = j
b.p = m
l.r = b
d.r = e
a.u = d
a.p = f
f.u = k
f.p = g
e.u = k
e.p = m
m.u = d
m.p = g
assert f.u.r.p.p.txt == "m"