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

b = A("b")
d = B("d")
n = A("n")
c = B("c")
k = A("k")
g = A("g")

b.p = n
b.q = c
d.u = g
n.p = g
n.q = d
c.u = k
k.p = g
k.q = d
g.p = n
g.q = c
assert b.p.q.u.p.p.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

b = A("b")
d = B("d")
n = A("n")
c = B("c")
k = A("k")
g = A("g")

b.p = n
b.q = c
d.u = g
n.p = g
n.q = d
c.u = k
k.p = g
k.q = d
g.p = n
g.q = c
assert b.p.q.u.p.p.txt == "g"