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

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

e = A("e")
n = B("n")
g = B("g")
k = A("k")

e.q = g
n.r = g
n.u = k
g.r = n
g.u = e
k.q = g
assert e.q.u.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

e = A("e")
n = B("n")
g = B("g")
k = A("k")

e.q = g
n.r = g
n.u = k
g.r = n
g.u = e
k.q = g
assert e.q.u.q.u.txt == "e"