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

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

h = A("h")
j = B("j")
e = A("e")
a = B("a")

h.y = e
h.x = j
j.v = h
j.w = a
e.y = h
e.x = j
a.v = e
a.w = j
assert e.y.y.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.x: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
e = A("e")
a = B("a")

h.y = e
h.x = j
j.v = h
j.w = a
e.y = h
e.x = j
a.v = e
a.w = j
assert e.y.y.y.x.txt == "j"