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.s: B = None
        self.r: A = None
        self.txt = txt

c = A("c")
k = B("k")
e = A("e")
b = A("b")
h = A("h")
a = B("a")
g = A("g")

c.p = b
c.q = a
k.s = a
k.r = b
e.p = b
e.q = a
b.p = c
b.q = k
h.p = g
h.q = a
a.s = k
a.r = e
g.p = b
g.q = k
assert h.p.q.r.q.s.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.s: B = None
        self.r: A = None
        self.txt = txt

c = A("c")
k = B("k")
e = A("e")
b = A("b")
h = A("h")
a = B("a")
g = A("g")

c.p = b
c.q = a
k.s = a
k.r = b
e.p = b
e.q = a
b.p = c
b.q = k
h.p = g
h.q = a
a.s = k
a.r = e
g.p = b
g.q = k
assert h.p.q.r.q.s.txt == "a"