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

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

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

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

d = A("d")
h = B("h")
b = C("b")
f = D("f")
a = C("a")
m = B("m")
e = B("e")
c = A("c")

d.v = c
h.x = d
h.t = f
b.r = f
f.z = c
f.s = c
a.r = f
m.x = d
m.t = f
e.x = d
e.t = f
c.v = d
assert c.v.v.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

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

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

d = A("d")
h = B("h")
b = C("b")
f = D("f")
a = C("a")
m = B("m")
e = B("e")
c = A("c")

d.v = c
h.x = d
h.t = f
b.r = f
f.z = c
f.s = c
a.r = f
m.x = d
m.t = f
e.x = d
e.t = f
c.v = d
assert c.v.v.v.v.v.v.v.txt == "d"