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

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

g = A("g")
h = B("h")
i = A("i")
k = B("k")
f = A("f")

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

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

g = A("g")
h = B("h")
i = A("i")
k = B("k")
f = A("f")

g.w = h
h.w = k
h.v = g
i.w = h
k.w = h
k.v = f
f.w = h
assert k.w.w.w.v.w.txt == "h"