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

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

b = A("b")
e = B("e")
g = A("g")
f = B("f")

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

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

b = A("b")
e = B("e")
g = A("g")
f = B("f")

b.u = e
e.w = g
g.u = e
f.w = b
assert f.w.u.w.u.txt == "e"