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

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

h = A("h")
g = B("g")
f = A("f")
l = B("l")
a = B("a")

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

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

h = A("h")
g = B("g")
f = A("f")
l = B("l")
a = B("a")

h.v = f
h.x = l
g.w = f
f.v = h
f.x = l
l.w = f
a.w = h
assert h.v.x.w.v.v.txt == "f"