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

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

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

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

c = A("c")
b = B("b")
h = C("h")
g = D("g")
j = A("j")

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

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

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

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

c = A("c")
b = B("b")
h = C("h")
g = D("g")
j = A("j")

c.y = g
c.s = h
c.p = j
b.q = h
b.y = h
b.s = h
b.o = c
h.p = b
g.v = c
g.s = b
j.y = g
j.s = h
j.p = c
assert h.p.o.y.v.txt == "c"