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

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

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

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

c = A("c")
f = B("f")
k = C("k")
h = D("h")

c.s = k
f.r = c
f.u = h
k.t = f
h.r = c
assert c.s.t.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

c = A("c")
f = B("f")
k = C("k")
h = D("h")

c.s = k
f.r = c
f.u = h
k.t = f
h.r = c
assert c.s.t.u.r.txt == "c"