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

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

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

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

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

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

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

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

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

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

f.r = c
j.r = c
k.s = j
k.u = j
c.r = j
c.u = k
assert k.u.r.r.txt == "j"