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

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

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

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

h = A("h")
a = B("a")
m = C("m")
f = D("f")

h.q = a
h.r = m
a.u = m
m.t = h
f.u = a
f.r = m
assert f.u.u.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.r: C = None
        self.txt = txt

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

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

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

h = A("h")
a = B("a")
m = C("m")
f = D("f")

h.q = a
h.r = m
a.u = m
m.t = h
f.u = a
f.r = m
assert f.u.u.t.q.txt == "a"