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

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

g = A("g")
l = B("l")
a = A("a")
h = B("h")
e = A("e")
n = B("n")
i = B("i")

g.u = n
l.p = a
l.q = n
a.u = h
h.p = a
h.q = i
e.u = l
n.p = g
n.q = h
i.p = g
i.q = n
assert e.u.q.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

g = A("g")
l = B("l")
a = A("a")
h = B("h")
e = A("e")
n = B("n")
i = B("i")

g.u = n
l.p = a
l.q = n
a.u = h
h.p = a
h.q = i
e.u = l
n.p = g
n.q = h
i.p = g
i.q = n
assert e.u.q.q.p.txt == "a"