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

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

e = A("e")
g = B("g")
c = B("c")
n = A("n")
j = B("j")
i = B("i")

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

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

e = A("e")
g = B("g")
c = B("c")
n = A("n")
j = B("j")
i = B("i")

e.y = c
e.s = n
g.q = c
c.q = i
n.y = i
n.s = e
j.q = c
i.q = j
assert e.s.s.s.s.txt == "e"