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

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

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

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

f.r = j
d.x = f
h.u = k
j.x = g
k.r = j
a.u = k
g.r = j
l.r = d
assert h.u.r.x.r.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

f.r = j
d.x = f
h.u = k
j.x = g
k.r = j
a.u = k
g.r = j
l.r = d
assert h.u.r.x.r.x.r.txt == "j"