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

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

c = A("c")
d = B("d")
f = A("f")
i = B("i")
b = B("b")
g = A("g")
e = B("e")
m = A("m")

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

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

c = A("c")
d = B("d")
f = A("f")
i = B("i")
b = B("b")
g = A("g")
e = B("e")
m = A("m")

c.p = f
c.u = g
d.q = i
f.p = m
f.u = c
i.q = d
b.q = i
g.p = m
g.u = m
e.q = d
m.p = g
m.u = f
assert m.p.u.u.p.u.p.p.txt == "g"