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.v: B = None
        self.s: A = None
        self.txt = txt

b = A("b")
m = B("m")
k = B("k")
j = A("j")

b.v = j
b.x = k
m.v = k
m.s = j
k.v = m
k.s = j
j.v = b
j.x = m
assert j.x.s.x.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.v: B = None
        self.s: A = None
        self.txt = txt

b = A("b")
m = B("m")
k = B("k")
j = A("j")

b.v = j
b.x = k
m.v = k
m.s = j
k.v = m
k.s = j
j.v = b
j.x = m
assert j.x.s.x.txt == "m"