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

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

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

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

f = A("f")
i = B("i")
l = C("l")
h = D("h")
c = B("c")
e = B("e")
a = C("a")
d = B("d")

f.r = l
i.q = h
l.s = a
h.u = f
c.q = h
e.q = h
a.s = l
d.q = h
assert f.r.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

f = A("f")
i = B("i")
l = C("l")
h = D("h")
c = B("c")
e = B("e")
a = C("a")
d = B("d")

f.r = l
i.q = h
l.s = a
h.u = f
c.q = h
e.q = h
a.s = l
d.q = h
assert f.r.s.s.s.txt == "a"