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

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

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

j.z = d
n.t = h
f.t = h
g.t = k
h.t = f
k.t = n
d.z = j
l.t = f
assert f.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

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

j.z = d
n.t = h
f.t = h
g.t = k
h.t = f
k.t = n
d.z = j
l.t = f
assert f.t.t.t.txt == "h"