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

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

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

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

g = A("g")
k = B("k")
l = C("l")
a = D("a")

g.r = k
k.s = l
k.r = l
k.o = a
l.r = a
a.p = k
a.z = k
assert g.r.s.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

g = A("g")
k = B("k")
l = C("l")
a = D("a")

g.r = k
k.s = l
k.r = l
k.o = a
l.r = a
a.p = k
a.z = k
assert g.r.s.r.z.txt == "k"