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

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

j = A("j")
g = B("g")
a = B("a")
l = A("l")

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

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

j = A("j")
g = B("g")
a = B("a")
l = A("l")

j.x = a
j.p = l
g.q = a
g.v = j
a.q = g
a.v = l
l.x = a
l.p = j
assert j.x.q.q.txt == "a"