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

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

h = A("h")
j = B("j")
l = A("l")

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

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

h = A("h")
j = B("j")
l = A("l")

h.v = j
h.x = l
j.q = l
l.v = j
l.x = h
assert l.v.q.v.txt == "j"