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

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

a = A("a")
c = B("c")
i = B("i")
d = A("d")

a.w = d
c.v = a
i.v = a
d.w = a
assert i.v.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.v: A = None
        self.txt = txt

a = A("a")
c = B("c")
i = B("i")
d = A("d")

a.w = d
c.v = a
i.v = a
d.w = a
assert i.v.w.w.w.txt == "d"