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

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

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

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

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

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

g.s = m
g.q = h
k.u = g
h.u = n
f.u = n
m.s = n
m.q = j
j.u = m
n.s = g
n.q = f
assert f.u.q.u.q.u.q.txt == "f"