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

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

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

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

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

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

n.q = i
n.t = j
i.x = c
g.q = e
g.t = n
c.x = i
e.x = c
j.q = c
j.t = g
assert e.x.x.x.x.txt == "i"