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

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

f = A("f")
j = B("j")
c = B("c")
d = B("d")
i = A("i")
n = A("n")
h = A("h")
a = A("a")

f.p = c
f.r = j
j.u = i
j.q = a
c.u = a
c.q = h
d.u = a
d.q = n
i.p = c
i.r = c
n.p = j
n.r = j
h.p = j
h.r = c
a.p = d
a.r = d
assert c.q.r.u.r.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: B = None
        self.txt = txt

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

f = A("f")
j = B("j")
c = B("c")
d = B("d")
i = A("i")
n = A("n")
h = A("h")
a = A("a")

f.p = c
f.r = j
j.u = i
j.q = a
c.u = a
c.q = h
d.u = a
d.q = n
i.p = c
i.r = c
n.p = j
n.r = j
h.p = j
h.r = c
a.p = d
a.r = d
assert c.q.r.u.r.q.r.q.txt == "a"