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

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

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

h.q = n
h.s = l
g.r = j
j.q = g
j.s = l
f.r = j
b.r = l
n.r = j
k.r = j
l.q = k
l.s = h
assert h.s.s.s.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: A = None
        self.txt = txt

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

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

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