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

g = A("g")
h = B("h")
d = A("d")
k = A("k")
c = B("c")
j = A("j")

g.s = c
g.q = h
h.s = d
h.r = k
d.s = h
d.q = c
k.s = h
k.q = c
c.s = d
c.r = g
j.s = c
j.q = c
assert j.q.s.s.s.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.s: A = None
        self.r: A = None
        self.txt = txt

g = A("g")
h = B("h")
d = A("d")
k = A("k")
c = B("c")
j = A("j")

g.s = c
g.q = h
h.s = d
h.r = k
d.s = h
d.q = c
k.s = h
k.q = c
c.s = d
c.r = g
j.s = c
j.q = c
assert j.q.s.s.s.q.txt == "c"