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

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

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

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

c = A("c")
a = B("a")
b = C("b")
j = D("j")
f = A("f")
m = B("m")
i = D("i")

c.y = f
a.o = c
a.q = b
a.w = b
a.r = j
b.x = a
b.o = f
j.p = c
j.v = b
j.t = b
f.y = c
m.o = c
m.q = b
m.w = b
m.r = j
i.p = f
i.v = b
i.t = b
assert m.r.p.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

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

c = A("c")
a = B("a")
b = C("b")
j = D("j")
f = A("f")
m = B("m")
i = D("i")

c.y = f
a.o = c
a.q = b
a.w = b
a.r = j
b.x = a
b.o = f
j.p = c
j.v = b
j.t = b
f.y = c
m.o = c
m.q = b
m.w = b
m.r = j
i.p = f
i.v = b
i.t = b
assert m.r.p.y.y.y.txt == "f"