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

class B:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

e.r = b
c.q = b
b.y = d
b.p = c
g.s = c
g.o = c
g.v = c
g.r = b
d.r = b
assert c.q.p.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

e.r = b
c.q = b
b.y = d
b.p = c
g.s = c
g.o = c
g.v = c
g.r = b
d.r = b
assert c.q.p.q.p.txt == "c"