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

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

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

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

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

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

d.o = j
d.q = e
j.s = d
e.o = j
e.q = d
assert d.q.o.s.txt == "d"