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

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

l = A("l")
h = B("h")
g = A("g")
f = B("f")

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

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

l = A("l")
h = B("h")
g = A("g")
f = B("f")

l.w = g
h.u = f
g.w = l
f.u = h
assert l.w.w.w.w.txt == "l"