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

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

class C:
    def __init__(self, txt: str):
        self.u: B = None
        self.y: D = None
        self.txt = txt

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

f = A("f")
l = B("l")
n = C("n")
c = D("c")
h = B("h")

f.o = c
l.q = n
l.s = h
n.u = h
n.y = c
c.r = h
h.q = n
h.s = l
assert f.o.r.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.u: B = None
        self.y: D = None
        self.txt = txt

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

f = A("f")
l = B("l")
n = C("n")
c = D("c")
h = B("h")

f.o = c
l.q = n
l.s = h
n.u = h
n.y = c
c.r = h
h.q = n
h.s = l
assert f.o.r.s.s.txt == "h"