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

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

k = A("k")
c = B("c")
h = A("h")
l = A("l")
e = B("e")
f = B("f")
a = B("a")

k.t = l
k.x = e
c.z = f
h.t = l
h.x = c
l.t = k
l.x = a
e.z = a
f.z = a
a.z = e
assert e.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: B = None
        self.txt = txt

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

k = A("k")
c = B("c")
h = A("h")
l = A("l")
e = B("e")
f = B("f")
a = B("a")

k.t = l
k.x = e
c.z = f
h.t = l
h.x = c
l.t = k
l.x = a
e.z = a
f.z = a
a.z = e
assert e.z.z.z.txt == "a"