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

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

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

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

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

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

n.u = g
n.q = k
k.t = j
g.u = n
g.q = f
j.t = f
f.t = j
assert j.t.t.t.txt == "f"