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

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

class C:
    def __init__(self, txt: str):
        self.q: A = None
        self.t: D = None
        self.o: B = None
        self.u: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
d = C("d")
g = D("g")

e.p = d
e.t = g
k.y = g
k.x = g
k.r = g
d.q = e
d.u = e
d.t = g
d.o = k
g.s = e
g.o = e
g.y = d
assert g.y.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.t: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.q: A = None
        self.t: D = None
        self.o: B = None
        self.u: A = None
        self.txt = txt

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

e = A("e")
k = B("k")
d = C("d")
g = D("g")

e.p = d
e.t = g
k.y = g
k.x = g
k.r = g
d.q = e
d.u = e
d.t = g
d.o = k
g.s = e
g.o = e
g.y = d
assert g.y.o.r.txt == "g"