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

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

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

f = A("f")
d = B("d")
k = C("k")
n = B("n")
g = A("g")
l = B("l")
h = A("h")
e = B("e")
m = C("m")

f.u = m
d.x = f
d.t = l
k.q = f
n.x = f
n.t = l
g.u = m
l.x = h
l.t = d
h.u = k
e.x = f
e.t = d
m.q = g
assert l.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

f = A("f")
d = B("d")
k = C("k")
n = B("n")
g = A("g")
l = B("l")
h = A("h")
e = B("e")
m = C("m")

f.u = m
d.x = f
d.t = l
k.q = f
n.x = f
n.t = l
g.u = m
l.x = h
l.t = d
h.u = k
e.x = f
e.t = d
m.q = g
assert l.t.t.t.txt == "d"