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

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

class C:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.y: B = None
        self.txt = txt

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

d = A("d")
j = B("j")
f = C("f")
i = D("i")
b = D("b")
k = A("k")

d.r = i
j.y = d
j.u = f
j.p = k
j.w = i
f.x = d
f.p = d
f.y = j
i.w = b
i.q = b
i.u = d
b.w = i
b.q = i
b.u = k
k.r = b
assert d.r.w.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: A = None
        self.y: B = None
        self.txt = txt

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

d = A("d")
j = B("j")
f = C("f")
i = D("i")
b = D("b")
k = A("k")

d.r = i
j.y = d
j.u = f
j.p = k
j.w = i
f.x = d
f.p = d
f.y = j
i.w = b
i.q = b
i.u = d
b.w = i
b.q = i
b.u = k
k.r = b
assert d.r.w.u.r.u.txt == "k"