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

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

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

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

b = A("b")
i = B("i")
g = C("g")
k = D("k")
n = B("n")
d = D("d")

b.r = g
i.w = k
i.x = k
i.r = b
i.y = g
g.s = b
g.z = b
k.s = i
k.y = i
k.r = d
n.w = d
n.x = d
n.r = b
n.y = g
d.s = n
d.r = k
d.y = i
assert i.r.r.s.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

b = A("b")
i = B("i")
g = C("g")
k = D("k")
n = B("n")
d = D("d")

b.r = g
i.w = k
i.x = k
i.r = b
i.y = g
g.s = b
g.z = b
k.s = i
k.y = i
k.r = d
n.w = d
n.x = d
n.r = b
n.y = g
d.s = n
d.r = k
d.y = i
assert i.r.r.s.r.z.r.txt == "g"