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

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

e = A("e")
k = B("k")
j = B("j")

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

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

e = A("e")
k = B("k")
j = B("j")

e.x = k
k.q = e
j.q = e
assert k.q.x.q.txt == "e"