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

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

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

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

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

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

j.v = a
j.t = h
h.x = m
a.v = j
a.t = m
m.x = h
assert m.x.x.x.txt == "h"