class A:
    def __init__(self, txt: str):
        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

g = A("g")
h = B("h")
l = A("l")
c = B("c")
b = A("b")
k = B("k")
n = A("n")

g.q = c
h.s = k
h.r = g
l.q = k
c.s = h
c.r = b
b.q = k
k.s = c
k.r = l
n.q = c
assert h.s.s.s.r.txt == "
class A:
    def __init__(self, txt: str):
        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

g = A("g")
h = B("h")
l = A("l")
c = B("c")
b = A("b")
k = B("k")
n = A("n")

g.q = c
h.s = k
h.r = g
l.q = k
c.s = h
c.r = b
b.q = k
k.s = c
k.r = l
n.q = c
assert h.s.s.s.r.txt == "g"