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

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

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

g.t = n
e.w = n
e.u = k
b.w = g
b.u = e
n.t = g
l.w = g
l.u = b
h.t = n
k.w = h
k.u = e
assert g.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

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

g.t = n
e.w = n
e.u = k
b.w = g
b.u = e
n.t = g
l.w = g
l.u = b
h.t = n
k.w = h
k.u = e
assert g.t.t.t.txt == "n"