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

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

b = A("b")
f = B("f")
e = B("e")
l = A("l")
a = B("a")
d = A("d")
i = B("i")
c = A("c")

b.p = d
b.u = i
f.r = c
f.x = e
e.r = b
e.x = f
l.p = c
l.u = a
a.r = l
a.x = i
d.p = b
d.u = f
i.r = b
i.x = e
c.p = b
c.u = f
assert d.u.x.r.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.u: B = None
        self.txt = txt

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

b = A("b")
f = B("f")
e = B("e")
l = A("l")
a = B("a")
d = A("d")
i = B("i")
c = A("c")

b.p = d
b.u = i
f.r = c
f.x = e
e.r = b
e.x = f
l.p = c
l.u = a
a.r = l
a.x = i
d.p = b
d.u = f
i.r = b
i.x = e
c.p = b
c.u = f
assert d.u.x.r.u.r.u.txt == "i"