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

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

e = A("e")
c = B("c")
d = A("d")
g = B("g")
j = B("j")

e.q = c
e.v = d
c.x = e
c.s = g
d.q = c
d.v = e
g.x = d
g.s = c
j.x = e
j.s = g
assert j.x.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: A = None
        self.txt = txt

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

e = A("e")
c = B("c")
d = A("d")
g = B("g")
j = B("j")

e.q = c
e.v = d
c.x = e
c.s = g
d.q = c
d.v = e
g.x = d
g.s = c
j.x = e
j.s = g
assert j.x.q.x.txt == "e"