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

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

d = A("d")
l = B("l")
f = B("f")
a = A("a")
j = B("j")
k = B("k")
h = B("h")

d.r = j
d.w = a
l.u = a
f.u = d
a.r = j
a.w = d
j.u = d
k.u = d
h.u = a
assert f.u.r.u.r.u.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: A = None
        self.txt = txt

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

d = A("d")
l = B("l")
f = B("f")
a = A("a")
j = B("j")
k = B("k")
h = B("h")

d.r = j
d.w = a
l.u = a
f.u = d
a.r = j
a.w = d
j.u = d
k.u = d
h.u = a
assert f.u.r.u.r.u.w.r.txt == "j"