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

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

k = A("k")
c = B("c")
f = A("f")
g = B("g")
l = A("l")
h = A("h")

k.s = c
k.q = g
c.p = f
c.w = g
f.s = g
f.q = g
g.p = h
g.w = c
l.s = g
l.q = g
h.s = g
h.q = c
assert c.w.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.q: B = None
        self.txt = txt

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

k = A("k")
c = B("c")
f = A("f")
g = B("g")
l = A("l")
h = A("h")

k.s = c
k.q = g
c.p = f
c.w = g
f.s = g
f.q = g
g.p = h
g.w = c
l.s = g
l.q = g
h.s = g
h.q = c
assert c.w.p.q.txt == "c"