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

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

h = A("h")
l = B("l")
i = B("i")
f = A("f")
e = A("e")

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

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

h = A("h")
l = B("l")
i = B("i")
f = A("f")
e = A("e")

h.p = i
h.q = l
l.u = e
i.u = h
f.p = l
f.q = l
e.p = l
e.q = i
assert l.u.p.u.q.u.txt == "h"