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

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

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

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

b = A("b")
l = B("l")
g = C("g")
n = D("n")
f = A("f")
m = C("m")
h = A("h")

b.v = n
l.y = f
g.v = l
g.p = m
n.u = g
n.p = l
f.v = n
m.v = l
m.p = g
h.v = n
assert f.v.p.y.v.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

b = A("b")
l = B("l")
g = C("g")
n = D("n")
f = A("f")
m = C("m")
h = A("h")

b.v = n
l.y = f
g.v = l
g.p = m
n.u = g
n.p = l
f.v = n
m.v = l
m.p = g
h.v = n
assert f.v.p.y.v.p.y.txt == "f"