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

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

k = A("k")
c = B("c")
d = A("d")

k.v = d
c.s = k
c.w = k
d.v = k
assert d.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

k = A("k")
c = B("c")
d = A("d")

k.v = d
c.s = k
c.w = k
d.v = k
assert d.v.v.v.txt == "k"