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

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

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

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

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

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

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