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

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

b = A("b")
a = B("a")
m = A("m")
g = B("g")
d = B("d")
l = A("l")
i = B("i")
f = A("f")
c = A("c")
n = A("n")

b.u = f
b.q = l
a.u = c
a.p = l
m.u = n
m.q = b
g.u = f
g.p = f
d.u = m
d.p = f
l.u = f
l.q = m
i.u = n
i.p = b
f.u = l
f.q = n
c.u = n
c.q = l
n.u = b
n.q = f
assert d.p.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.q: A = None
        self.txt = txt

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

b = A("b")
a = B("a")
m = A("m")
g = B("g")
d = B("d")
l = A("l")
i = B("i")
f = A("f")
c = A("c")
n = A("n")

b.u = f
b.q = l
a.u = c
a.p = l
m.u = n
m.q = b
g.u = f
g.p = f
d.u = m
d.p = f
l.u = f
l.q = m
i.u = n
i.p = b
f.u = l
f.q = n
c.u = n
c.q = l
n.u = b
n.q = f
assert d.p.u.u.u.u.txt == "f"