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

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

f = A("f")
a = B("a")
b = B("b")
n = B("n")
e = A("e")
c = A("c")

f.u = n
a.w = n
a.r = b
b.w = a
b.r = n
n.w = b
n.r = b
e.u = n
c.u = n
assert b.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

f = A("f")
a = B("a")
b = B("b")
n = B("n")
e = A("e")
c = A("c")

f.u = n
a.w = n
a.r = b
b.w = a
b.r = n
n.w = b
n.r = b
e.u = n
c.u = n
assert b.w.w.w.w.txt == "a"