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

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

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

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

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

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

c.q = j
j.s = c
j.o = c
g.s = c
g.o = c
assert g.o.q.o.txt == "c"