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

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

l = A("l")
j = B("j")
h = A("h")
e = B("e")
c = A("c")

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

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

l = A("l")
j = B("j")
h = A("h")
e = B("e")
c = A("c")

l.p = h
l.q = e
j.u = c
h.p = c
h.q = j
e.u = l
c.p = h
c.q = e
assert c.p.p.q.txt == "e"