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

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

d = A("d")
a = B("a")
e = A("e")

d.w = a
a.v = d
e.w = a
assert a.v.w.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

d = A("d")
a = B("a")
e = A("e")

d.w = a
a.v = d
e.w = a
assert a.v.w.v.txt == "d"