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

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

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

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

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

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

f.x = h
f.v = h
h.x = a
i.x = h
i.v = k
k.x = a
a.x = h
assert i.v.x.x.x.txt == "a"