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.txt = txt

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

g.r = d
g.p = e
m.u = g
f.r = j
f.p = b
e.r = l
e.p = g
l.u = b
j.u = g
d.u = g
b.r = j
b.p = f
assert l.u.p.r.u.r.u.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.txt = txt

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

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