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

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.s: B = None
        self.x: A = None
        self.txt = txt

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

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

c = A("c")
e = B("e")
g = C("g")
i = D("i")
d = D("d")
m = C("m")
l = B("l")
b = A("b")

c.p = d
e.t = c
e.s = l
e.x = b
g.z = c
g.o = e
g.r = d
i.y = b
d.y = b
m.z = b
m.o = e
m.r = i
l.t = c
l.s = e
l.x = b
b.p = i
assert g.r.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.s: B = None
        self.x: A = None
        self.txt = txt

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

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

c = A("c")
e = B("e")
g = C("g")
i = D("i")
d = D("d")
m = C("m")
l = B("l")
b = A("b")

c.p = d
e.t = c
e.s = l
e.x = b
g.z = c
g.o = e
g.r = d
i.y = b
d.y = b
m.z = b
m.o = e
m.r = i
l.t = c
l.s = e
l.x = b
b.p = i
assert g.r.y.p.txt == "i"