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

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

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

j = A("j")
d = B("d")
f = C("f")
c = C("c")
h = A("h")
n = B("n")

j.t = n
j.r = f
d.w = h
d.y = n
f.x = c
f.w = n
c.x = f
c.w = d
h.t = d
h.r = f
n.w = h
n.y = d
assert f.x.w.y.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: C = None
        self.txt = txt

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

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

j = A("j")
d = B("d")
f = C("f")
c = C("c")
h = A("h")
n = B("n")

j.t = n
j.r = f
d.w = h
d.y = n
f.x = c
f.w = n
c.x = f
c.w = d
h.t = d
h.r = f
n.w = h
n.y = d
assert f.x.w.y.w.r.txt == "f"