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.txt = txt

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

d.t = b
k.w = f
f.t = b
l.w = j
j.t = f
g.w = j
n.w = b
b.t = j
i.w = d
assert l.w.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.txt = txt

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

d.t = b
k.w = f
f.t = b
l.w = j
j.t = f
g.w = j
n.w = b
b.t = j
i.w = d
assert l.w.t.t.t.txt == "j"