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

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

f = A("f")
d = B("d")
n = B("n")
g = A("g")
m = A("m")
j = B("j")
c = B("c")
a = A("a")

f.q = d
f.s = n
d.s = c
d.p = g
n.s = d
n.p = a
g.q = d
g.s = d
m.q = j
m.s = n
j.s = c
j.p = g
c.s = d
c.p = m
a.q = n
a.s = j
assert d.p.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.txt = txt

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

f = A("f")
d = B("d")
n = B("n")
g = A("g")
m = A("m")
j = B("j")
c = B("c")
a = A("a")

f.q = d
f.s = n
d.s = c
d.p = g
n.s = d
n.p = a
g.q = d
g.s = d
m.q = j
m.s = n
j.s = c
j.p = g
c.s = d
c.p = m
a.q = n
a.s = j
assert d.p.s.p.txt == "g"