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

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

g = A("g")
h = B("h")
e = B("e")
m = B("m")
f = B("f")
l = A("l")
c = A("c")
j = B("j")
i = B("i")
k = A("k")

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

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

g = A("g")
h = B("h")
e = B("e")
m = B("m")
f = B("f")
l = A("l")
c = A("c")
j = B("j")
i = B("i")
k = A("k")

g.p = h
h.u = m
h.q = m
e.u = j
e.q = i
m.u = j
m.q = h
f.u = j
f.q = m
l.p = m
c.p = f
j.u = h
j.q = f
i.u = f
i.q = j
k.p = i
assert c.p.q.u.q.txt == "f"