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

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

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

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

g = A("g")
e = B("e")
n = C("n")
h = D("h")
l = B("l")
i = B("i")
f = C("f")

g.p = h
e.s = i
n.q = l
n.v = f
h.p = g
h.x = f
l.s = i
i.s = e
f.q = e
f.v = n
assert i.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

g = A("g")
e = B("e")
n = C("n")
h = D("h")
l = B("l")
i = B("i")
f = C("f")

g.p = h
e.s = i
n.q = l
n.v = f
h.p = g
h.x = f
l.s = i
i.s = e
f.q = e
f.v = n
assert i.s.s.s.s.txt == "i"