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

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

e = A("e")
h = B("h")
m = A("m")
j = B("j")
a = A("a")
l = A("l")
c = B("c")
i = A("i")

e.p = c
e.q = m
h.t = a
m.p = j
m.q = e
j.t = l
a.p = h
a.q = m
l.p = c
l.q = e
c.t = i
i.p = j
i.q = m
assert a.q.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.q: A = None
        self.txt = txt

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

e = A("e")
h = B("h")
m = A("m")
j = B("j")
a = A("a")
l = A("l")
c = B("c")
i = A("i")

e.p = c
e.q = m
h.t = a
m.p = j
m.q = e
j.t = l
a.p = h
a.q = m
l.p = c
l.q = e
c.t = i
i.p = j
i.q = m
assert a.q.p.t.txt == "l"