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

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

b = A("b")
g = B("g")
d = B("d")
e = A("e")

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

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

b = A("b")
g = B("g")
d = B("d")
e = A("e")

b.s = e
b.x = e
g.q = d
d.q = g
e.s = b
e.x = b
assert g.q.q.q.txt == "d"