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.y: A = None
        self.txt = txt

h = A("h")
m = B("m")
c = A("c")
b = B("b")
a = A("a")

h.x = m
h.v = m
m.y = a
c.x = m
c.v = b
b.y = c
a.x = m
a.v = m
assert a.v.y.v.y.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.y: A = None
        self.txt = txt

h = A("h")
m = B("m")
c = A("c")
b = B("b")
a = A("a")

h.x = m
h.v = m
m.y = a
c.x = m
c.v = b
b.y = c
a.x = m
a.v = m
assert a.v.y.v.y.x.txt == "m"