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

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

a = A("a")
c = B("c")
h = A("h")
k = A("k")

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

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

a = A("a")
c = B("c")
h = A("h")
k = A("k")

a.v = h
a.w = c
c.w = k
h.v = k
h.w = c
k.v = a
k.w = c
assert h.w.w.w.w.txt == "k"